Here is how I'm sending email through Gmail App.
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();
}
It's not starting the Gmail App but shows the following message.
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
There are few questions regarding this on SOF and most of them are suggested to use exported = true. But I cannot use this solution as I'm launching the activity of another app. Could you please guide me?
Sending binary contentIntent shareIntent = new Intent(); shareIntent. setAction(Intent. ACTION_SEND);
Try this
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/html");
final PackageManager pm = this.getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
String className = null;
for (final ResolveInfo info : matches) {
if (info.activityInfo.packageName.equals("com.google.android.gm")) {
className = info.activityInfo.name;
if(className != null && !className.isEmpty()){
break;
}
}
}
emailIntent.setClassName("com.google.android.gm", className);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With