how to check whether email client installed on device

匿名 (未验证) 提交于 2019-12-03 08:52:47

问题:

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, "vin@gmail.com");     List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.GET_META_DATA);     return list.size() > 0; } 

回答1:

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; }


回答2:

For email client, specifically, you should use:

intent.setType("message/rfc822");

instead of:

intent.setType("text/html");


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!