How to create a selector for a list of applications using the package manager

Basically I have a list of package names for popular email applications, and I want to create a choice to trigger the intention of sending email, you can refer to this  question, here it uses the package manager for gmail only, I want to do this for a list of packages

0
source share
2 answers

What I want to do is simulate the behavior of the desktop when you click on the email link that opens the outlook / gmail client with the field specified for the email id, but in addition to this, I want the user to select an address email application launch

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

where you replace yourEmailAddressGoesHerewith "email id".

If the user has more than one mail client and the user has not selected the default mail client, the user will automatically get a choice. If the user has only one email client or has selected the default email client, this will lead the user to some activity to compose a message to the email address you specified.

+2
source

uri

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

. , , , , , . ,

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

, ,

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();
}
+2

Source: https://habr.com/ru/post/1752412/


All Articles