I need to check whether email client is installed on a device or not. I have used the following code but it does not work for me.
public boolean isIntentAvailable() {
final PackageManager packageManager = getApplicationContext().getPackageManager();
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_META_DATA);
return list.size() > 0;
}
A Gmail client is an email client specifically for Gmail users. You likely already use at least one Gmail client — if you use IMAP to read your Gmail messages via the email app on your Android, iPhone, or other mobile device, you're already using a Gmail client.
Use this, works for me :
public static boolean isMailClientPresent(Context context){
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
final PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0);
if(list.size() == 0)
return false;
else
return true;
}
For email client, specifically, you should use:
intent.setType("message/rfc822");
instead of:
intent.setType("text/html");
use this method:
private fun sendEmail(to: Array<String>) {
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("mailto:") // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, to)
// intent.putExtra(Intent.EXTRA_SUBJECT, subject)
if (intent.resolveActivity(requireContext().packageManager) != null) {
startActivity(intent)
}
}
To be able to check for email clients when targeting api 30, add "queries" to the Manifest:
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="*" />
</intent>
</queries>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With