How to create an intention to run any email application?

I found various topics here and elsewhere, creating the intention of sending emails, and this seems pretty simple. I am looking for the intention of simply launching any email client that the user may have.

Here is the code that I saw for sending an email ( published for reference only, this does not satisfy my needs since I do not want to send a new message ):

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("text/plain"); 
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"}); 
i.putExtra(Intent.EXTRA_SUBJECT, "Subject of the message"); 
i.putExtra(Intent.EXTRA_TEXT   , "Body of the message"); 

Here is the code I compiled for a specific Gmail client launch by package name:

PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.google.android.gm");
startActivity(intent);

The code above works, but is not flexible in that the user may not use Gmail, but another embedded email application or a third-party email application. I am looking for an intention that will lead to a choice in this case, so that the user can decide which application will be launched to read email.

Does anyone know how to do this?

+3
source share
3 answers

Does anyone know how to accomplish this?

There is no such thing Intent- you can tell it by examining the manifest for the email application.

, , - , , PackageManager, .

0

- URL- mailto ? ---- , :

mt = MailTo.parse("mailto:yourname@gmail.com");
sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{mt.getTo()});
sendIntent.putExtra(Intent.EXTRA_TEXT, "");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Enter a subject");
sendIntent.setType("message/rfc822");
startActivity(Intent.createChooser(sendIntent, "Send a Message:"));
+5

Intent.createChooser(); .

BTW

+1
source

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


All Articles