0

this is my code to invoke gmail.

private void sendMail() {
    // Device model
    String PhoneModel = android.os.Build.MODEL;
    // Android version
    String AndroidVersion = android.os.Build.VERSION.RELEASE;

    final Intent emailIntent = new Intent(
            android.content.Intent.ACTION_SEND);

    emailIntent.setType("plain/text");

    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
            new String[] { "****@gmail.com"});

    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
            "'some feedbace...");

    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "—— phoneModel:"
            + PhoneModel + ";ROM:" + AndroidVersion);

    startActivity(Intent.createChooser(emailIntent, "Sending mail..."));
}

when i click the menu to invoke the gmail to send feedback,the bluetooth come out too,with the gmail,and waiting for me to select one.but i just want to invoke the gmail app.what's wrong with my code .anybody help please!

smileVann
  • 554
  • 1
  • 6
  • 15
  • 1
    Gmail is not a valid answer. Not everybody uses Gmail. Some Android devices do not have Gmail. – CommonsWare Mar 03 '12 at 12:55
  • i just want an email application to send it ,but when i clicked ,the bluetooth also come out.i don't know how to filter the bluetooth out – smileVann Mar 03 '12 at 14:10

3 Answers3

1

You can try this:

emailIntent.setType("application/octet-stream");

Or alternatively you can use PackageManager to build a more limited set of Intents, and show your own dialog for the user to select their email app.

but actually you are swimming against the tide of Android with what you're doing. Android is designed to allow for a message to be "Sent" and to show all apps that accept that intent, so be careful you don't remove options the user may actually want.

Ollie C
  • 28,313
  • 34
  • 134
  • 217
  • i tried what you said,but the problem remained.i just want users to send some feedback by email instead of bluetooth.but i can't remove it from the opitions.i know it's possible,because i know a app reached – smileVann Mar 03 '12 at 13:17
0

You can try using android.content.Intent.ACTION_SENDTO instead of ACTION_SEND. If you have multiple email clients installed it will still prompt you to choose one though.

Have a look at this question for more info.

If you absolutely have to use Gmail and not have android prompt the user you can try what is suggested in this answer (Note: I haven't tried this):

If you specifically want GMail, you have to be a bit cleverer. (Note that the correct MIME type is actually "text/plain", not "plain/text". Do to an implementation oddity, GMail seems to be the only activity which responds to the latter, but this isn't a behavior I would count on.)

Community
  • 1
  • 1
Nick
  • 748
  • 1
  • 5
  • 23
  • thanks very much,at first.i don't specifically want gmail,just want some email application,instead of bluetooth. if i use .ACTION_SENDTO i will have a "no application ..."error.but thanks all the same. – smileVann Mar 03 '12 at 13:52
  • @irain: `ACTION_SENDTO` works perfectly well with `mailto:` `Uri` values. – CommonsWare Mar 03 '12 at 14:14
0
private void sendMail() {
    String body = "\n 机型:" + android.os.Build.MODEL + ";ROM:"
            + android.os.Build.VERSION.RELEASE;
    Uri mailUri = Uri.parse("mailto:byirain@gmail.com");
    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, mailUri);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "'易学堂'问题反馈与建议");
    emailIntent.putExtra(Intent.EXTRA_TEXT, body);
    startActivity(emailIntent);
}

I finally finished it, though the uri, like before

kapex
  • 28,903
  • 6
  • 107
  • 121
smileVann
  • 554
  • 1
  • 6
  • 15