我是新手,但我的代码 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/