1

Intent.ACTION_SENDTO in shows two options but my clent is asking to remove the gmail option and i don't see a way out please help me

  Intent emailIntent =
 new Intent(Intent.ACTION_SENDTO,
 Uri.fromParts( "mailto",userInput.getText().toString(), null));
 emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Press Release");
 emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Please view this press release");
 startActivity(Intent.createChooser(emailIntent,"Send mail using..."));

enter image description here

NavinRaj Pandey
  • 1,674
  • 2
  • 26
  • 40

2 Answers2

4

Use emailIntent.setPackage(PackageName of Email app); before calling startActivity.


You need to set email client package name but, in Samsung devices com.sec.android.email is the default In-Built Mail client, but in HTC it is com.htc.android.mail and so on. So first you need to filter that application and then set to intent. I am adding the solution

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
        "mailto", userInput.getText().toString(), null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Press Release");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
        "Please view this press release");

// Identify the package name of email client and set to intent
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(emailIntent, 0);
if (!resInfo.isEmpty()) {
    for (ResolveInfo info : resInfo) {
        if (info.activityInfo.packageName.toLowerCase().contains(".android.email")
                || info.activityInfo.name.toLowerCase().contains(".android.email")) {
            emailIntent.setPackage(info.activityInfo.packageName);
            // And now call
            startActivity(Intent.createChooser(emailIntent, "Send mail using..."));
        }
    }
}

You should read Android: How to get the native Email clients package name

Community
  • 1
  • 1
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
  • 2
    i think `com.google.android.gm` is a packagename of Gmail app while question is about **but my clent is asking to remove the gmail option** – SilentKiller Sep 01 '14 at 09:28
0

IF YOU WANT TO REMOVE GMAIL CLIENT FROM LIST create a custom cooser

  List<Intent> intents = new ArrayList<Intent>();
            Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
            sendIntent.setType("text/plain");
            List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(sendIntent, 0);
            if (!resInfo.isEmpty()){
                for (ResolveInfo resolveInfo : resInfo) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    Intent neededShareIntent = new Intent(android.content.Intent.ACTION_SEND);
                    neededShareIntent.setType("text/plain");
                    neededShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
                    neededShareIntent.setPackage(packageName);
                    if (!StringUtils.equals(packageName, "com.google.android.gm")){
                        intents.add(neededShareIntent);
                    }

                }
                Intent chooserIntent = Intent.createChooser(intents.remove(0), "Select app to share");

                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toArray(new Parcelable[]{}));

                startActivity(chooserIntent);
            }

Pls test this code and check

Deniz
  • 12,332
  • 10
  • 44
  • 62