android - 邮寄到 Android : 'Unsupported action' error

标签 android email mobile mailto

我是新手,但我的代码 fragment 有什么问题? 当我选择链接时,出现错误:“当前不支持此操作”。 这是我的代码:

public void addEmail() {

    TextView txt = (TextView) findViewById(R.id.emailtext);

    txt.setOnClickListener(new View.OnClickListener(){


        public void onClick(View v){
            Intent intent = new Intent();
            String uriText =
                    "mailto:youremail@gmail.com" + 
                    "?subject=" + URLEncoder.encode("some subject text here") + 
                    "&body=" + URLEncoder.encode("some text here");

                Uri uri = Uri.parse(uriText);

                Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
                sendIntent.setData(uri);
                startActivity(Intent.createChooser(sendIntent, "Send email")); 

    }});

}

非常感谢!

最佳答案

问题可能是您正在运行官方 Android 模拟器之一,但您尚未在其上设置电子邮件帐户。发生这种情况时,模拟器会打开 com.android.fallback.Fallback Activity ,但这似乎不会发生在真实世界的设备上。

您可以在尝试使用此代码启动 Intent 之前检测到这一点:

ComponentName emailApp = intent.resolveActivity(getPackageManager());
ComponentName unsupportedAction = ComponentName.unflattenFromString("com.android.fallback/.Fallback");
boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction);

关于android - 邮寄到 Android : 'Unsupported action' error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27528236/

相关文章:

android - 离线如何在我的Android Studio中安装gradle?

html - outlook 2013 浏览器内收件箱正在向我的表格添加样式属性并破坏对齐

ruby-on-rails - 使用 Rails 进行移动 API 身份验证

jquery - $.ajax + 身份验证 + 用户名中的 `@`

javascript - chrome mobile,jquery .ready() 未按预期触发

java - 使用 Appium 进行自动化时无法更改我的 Android 应用程序的个人资料图像

android - 如何使用电子邮件身份验证允许对 Firebase 数据库进行读/写访问

android - 在 Java 代码中获取自定义属性的值

android - 如何在android中设置多个闹钟

php - Laravel 5.1 Mail::send .env 配置不起作用