Skip to content Skip to sidebar Skip to footer

How To Create A Chooser For A List Of Applications Using Package Manager

Basically I have a list of package names for popular email apps, and I want to create a chooser to launch the send email intent, you can refer to this question, here he uses the p

Solution 1:

What I want to do is simulate the desktop behavior when you click on an email link which opens outlook/gmail client with the to field set to the email id, but in addition to this I want to let the user choose the email application that is launched

startActivity(new Intent(Intent.ACTION_SENDTO)
  .setData(Uri.parse("mailto:"+yourEmailAddressGoesHere)));

where you replace yourEmailAddressGoesHere with "the email id".

If the user has more than one email client, and the user has not chosen a default email client, the user will get a chooser automatically. If the user has only one email client, or has chosen a default email client, this will lead the user to some activity to compose a message to your designated email address.

Solution 2:

Create the intent add set its uri data

Intentintent=newIntent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);

then create the chooser intent. It's useful when you want the user to choose the app he wants every time he sends an email. If you want to choose an app and make it a default, you can omit the chooser and start the intent directly

Intentchooser= Intent.createChooser(intent, "Chooser title");

then check if there is at least one activity that can handle the email intent

if(intent.resolveActivity(getPackageManager()) != null){
    // there are apps, start the chooser
    startActivity(chooser);
} else {
    // no apps found
    Toast.makeText(this, "No apps found", Toast.LENGTH_SHORT).show();
}

Post a Comment for "How To Create A Chooser For A List Of Applications Using Package Manager"