简体   繁体   中英

Android Pay - How to detect if Android Pay is installed?

There is this code (taken from https://stackoverflow.com/a/5016624/1369016 ):

private boolean isAppInstalled(String packageName) {
   PackageManager pm = getPackageManager();
   boolean installed = false;
   try {
      pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
      installed = true;

   } catch (PackageManager.NameNotFoundException e) {
      installed = false;
   }
   return installed;
}

But I don't know what to put in the packageName. I tried com.google.android.gms.wallet (which is the package of some Wallet fragments used by Android Pay) but the above method returns false.

It turns out the package name required is " com.google.android.apps.walletnfcrel ". With that you can call the method in the question to detect if Android Pay is installed.

on Kotlin:

private fun isAppInstalled(packageName: String): Boolean {
    return try {
        activity?.packageManager?.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
        true
    } catch (e: PackageManager.NameNotFoundException) {
        false
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM