I wrote some application ( marshmallow sdk ) that in some action i need to send mail with some file attached using the default device account to well know user.
When i trying to use my sending action ( code attached ) i getting some dialog that tell me to choose the application that i want to use for this shared this file attached.
I want to skip this dialog somehow and just make this sending action be done without give the user that use this application to choose the gmail and press the 'send' button.
( like sending the mail in the background )
The code:
public void SendToMail(String filePath)
{
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"somemailAddress@gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Reminder");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Null");
File file = new File(filePath);
if (!file.exists() || !file.canRead()) {
return;
}
Uri uri = Uri.fromFile(file);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
final PackageManager pm = _context.getApplicationContext().getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
ResolveInfo best = null;
for(final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") || info.activityInfo.name.toLowerCase().contains("gmail"))
best = info;
if (best != null)
emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
_context.startActivity(emailIntent);
}