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!
You can try this:
ReplyDeleteemailIntent.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.
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.
ReplyDeleteHave 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.)
private void sendMail() {
ReplyDeleteString 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