When I want to send some text with an email client on the device, is it possible to see what email client (e.g. Gmail or Yahoo mail) has been开发者_StackOverflow中文版 chosen before I set the email text in the intent?
Unfortunately, no. When you launch the chooser intent, it's up to the user to decide where to go/what to use. All data has to be set before launching the intent, and you have no control until the activity returns. In other words, you cannot affect the text of the message based on their choice in the dialog.
This can't be accomplished using the default intent chooser. However, you can query which activities can respond to your intent:
PackageManager manager = getPackageManager();
List<ResolveInfo> ri = manager.queryIntentActivities(intent,
PackageManager.GET_RESOLVED_FILTER);
You could then proceed to display this in a list, observe which selection the user made and perform some selection-specific intent.
you can explicitly call your desired component to do your service. I want to send email using gmail like
public void sendGmail(Activity activity, String subject, String text) {
Intent gmailIntent = new Intent();
gmailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
gmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
gmailIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
try {
activity.startActivity(gmailIntent);
} catch(ActivityNotFoundException ex) {
// handle error
}
}
And don't forget to add Internet permission
精彩评论