0

I have the following code which used to send text from my app to Email:

Intent mail = new Intent(Intent.ACTION_VIEW);
            mail.setClassName("com.google.android.gm","com.google.android.gm.ComposeActivityGmail");
                mail.putExtra(Intent.EXTRA_EMAIL, new String[] {  });
                mail.setData(Uri.parse(""));
                mail.putExtra(Intent.EXTRA_SUBJECT, "Country Decryption");
                mail.setType("plain/text");
                mail.putExtra(Intent.EXTRA_TEXT, "my text");
                ctx.startActivity(mail);  

It works , but as you see, it uses Gmail app, how do I make it use Email application instead of Gmail?

I mean this app: email app

and what about sharing to Facebook ? I found that Facebook does not support sharing using intent anymore, and I have to use Facebook SDK, but I couldn't find any simple procedure to do that. Is there any simple way?

Regards.

Eenvincible
  • 5,641
  • 2
  • 27
  • 46
MSMC
  • 141
  • 1
  • 5
  • 16
  • I am thinking you could just filter all apps that use the SEND intents. For Faceboo SDK, their developer page has some useful documentation https://developers.facebook.com/docs/android – Eenvincible May 03 '16 at 15:12
  • There is no requirement that a device have an app named "Email", and there is no requirement for devices that *do* have an app named "Email" to all have the *same* app named "Email". And, there is no requirement for the user to want to use "Email" or Gmail for sending email messages, as they may prefer some other email client. – CommonsWare May 03 '16 at 15:47
  • thanks dear, but i mean by Email the default mail app used in android ! it come integrated with any android phone ! go to any thing in your phone and click share via ! you will find Email app which i talked about. – MSMC May 03 '16 at 15:52

3 Answers3

7

well to use other email apps am afraid you would have to create a chooser dialog and let the user choose which app to use, something like this

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
        "mailto","abc@mail.com", null));
emailIntent.putExtra(Intent.EXTRA_EMAIL, "address");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send Email..."));
Prateek Gupta
  • 835
  • 10
  • 18
Atiq
  • 14,435
  • 6
  • 54
  • 69
1

You have to create a specific filter on your ACTION_SEND and you can read a complete answer here.

This is the code in which you can choose which app show in the app chooser

List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();        
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if(packageName.contains("android.email")) {
            emailIntent.setPackage(packageName);
        } else if(packageName.contains("twitter") || packageName.contains("facebook") || packageName.contains("mms") || packageName.contains("android.gm")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            if(packageName.contains("twitter")) {
                intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_twitter));
            } else if(packageName.contains("facebook")) {
                // Warning: Facebook IGNORES our text. They say "These fields are intended for users to express themselves. Pre-filling these fields erodes the authenticity of the user voice."
                // One workaround is to use the Facebook SDK to post, but that doesn't allow the user to choose how they want to share. We can also make a custom landing page, and the link
                // will show the <meta content ="..."> text from that page with our link in Facebook.
                intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_facebook));
            } else if(packageName.contains("mms")) {
                intent.putExtra(Intent.EXTRA_TEXT, resources.getString(R.string.share_sms));
            } else if(packageName.contains("android.gm")) { // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                intent.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share_email_subject));               
                intent.setType("message/rfc822");
            }

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }
Community
  • 1
  • 1
michoprogrammer
  • 1,159
  • 2
  • 18
  • 45
0

This works to intent just the gmail app.

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.setPackage("com.google.android.gm");
        String shareBody = "Here is the share content body";
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
        startActivity(sharingIntent);
pm dubey
  • 976
  • 11
  • 16