0

I want to get emails from users. I am trying to filter the chooser intent but i am stuck at some point.

Chooser intent brings the user's contacts. I just want to show the installed email apps, with 'to' field auto filled of course.

How can I remove user's contacts and show email apps only?

any help would be greatly appreciated.

here is my code so far:

    List<Intent> emailAppLauncherIntents = new ArrayList<>();

    Intent emailAppIntent = new Intent(Intent.ACTION_SENDTO);
    emailAppIntent.setData(Uri.parse("mailto:test@mail.com"));
    emailAppIntent.putExtra(Intent.EXTRA_EMAIL, "");
    emailAppIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback on "+getContext().getPackageName());
    emailAppIntent.putExtra(Intent.EXTRA_TEXT, mailBody);

    PackageManager packageManager = getActivity().getPackageManager();

    List<ResolveInfo> emailApps = packageManager.queryIntentActivities(emailAppIntent, PackageManager.MATCH_ALL);

    for (ResolveInfo resolveInfo : emailApps) {
        String packageName = resolveInfo.activityInfo.packageName;
        Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
        emailAppLauncherIntents.add(launchIntent);
    }

    Intent chooserIntent = Intent.createChooser(new Intent(), "Select email app:");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, emailAppLauncherIntents.toArray(new Parcelable[emailAppLauncherIntents.size()]));
    startActivity(chooserIntent);
eren
  • 46
  • 6

2 Answers2

0

Changing the MIME type is the answer

Use

intent.setType("message/rfc822");
Arun Shankar
  • 2,295
  • 16
  • 20
  • thank you Arun. but i can't make it run with your code. `all apps associated with this action have been turned off blocked or are not installed` – eren Jun 09 '17 at 08:50
0

this is how i made it.

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri data = Uri.parse("mailto:"
            + "xyz@abc.com"
            + "?subject=" + "Feedback" + "&body=" + "");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Feedback";
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "xyz@abc.com" });
    intent.putExtra(Intent.EXTRA_TEXT, mailBody);
    intent.setData(data);
    startActivity(intent);
eren
  • 46
  • 6