以下是我通过Gmail应用发送电子邮件的方式.
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
emailIntent.setType("text/html");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Puzzle");
emailIntent.putExtra(Intent.EXTRA_TEXT, someTextHere));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachmentFile));
try {
startActivityForResult(emailIntent, SHARE_PUZZLE_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
showToast("No application found on this device to perform share action");
} catch (Exception e) {
showToast(e.getMessage());
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
它没有启动Gmail应用程序,但显示以下消息.
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.SEND typ=text/html cmp=com.google.android.gm/.ComposeActivityGmail (has extras) } from ProcessRecord{8293c64 26854:com.xxx.puzzleapp/u0a383} (pid=26854, uid=10383) not exported from uid 10083
Run Code Online (Sandbox Code Playgroud)
关于SOF的问题很少,建议大多数使用exported = true.但我无法使用此解决方案,因为我正在启动另一个应用程序的活动.你能指导我吗?
android-intent android-securityexception android-6.0-marshmallow