Checking through intent if user has certain messaging app installed android

微笑、不失礼 提交于 2019-12-13 07:27:44

问题


I am working with this code which Ragu Swaminathan helped me with on my original post found at: How to show both texting and dialer apps with a single Intent on Android?.

final List<Intent> finalIntents = new ArrayList<Intent>();
final Intent textIntent = new Intent(Intent.ACTION_VIEW);
textIntent.setType("text/plain");
textIntent.setData(Uri.parse("sms:"));
final PackageManager packageManager = getActivity().getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(textIntent, 0);
for (ResolveInfo res : listCam) {
  final String packageName = res.activityInfo.packageName;
  final Intent intent = new Intent(textIntent);
  intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
  intent.setPackage(packageName);
  finalIntents.add(intent);
}

Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:121"));
Intent chooserIntent = Intent.createChooser(
        callIntent, "Select app to share");

chooserIntent.putExtra(
        Intent.EXTRA_INITIAL_INTENTS, finalIntents.toArray(new Parcelable[]{}));

startActivity(chooserIntent);

I have this code that brings up snackup separating sms and dialer apps installed on users phone and allows them to pick one to either send a message / call a person.

What I want to know is, is it possbile to add another section on this snackbar that checks if the user has whatsapp installed or another specfic app installed.

Also, being new to android, I have tried playing around with the code but ended up messing it up. another thing that I would like to do is create sections like theses;

Sms apps:

.....

.....

.....

Dialer apps:

.....

.....

.....

Whatsapp:

.....

Any help is welcomed, please let me know if my question is not clear.

Edited;


回答1:


You can use getPackageInfo method

PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageInfo(certainAppPackageName, 0);

if (pi != null) {
    //app is installed, do smth
}

Google play links exist package names. For example:

 https://play.google.com/store/apps/details?id=org.telegram.messenger

where org.telegram.messenger is a package name



来源:https://stackoverflow.com/questions/34998759/checking-through-intent-if-user-has-certain-messaging-app-installed-android

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