Android Pay - 如何检测是否安装了 Android Pay?
Android Pay - How to detect if Android Pay is installed?
有这段代码(取自):
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;
}
但我不知道在 packageName 中放什么。我试过com.google.android.gms.wallet
(是AndroidPay使用的一些Wallet碎片的封装)但是上面的方法returns false.
原来需要的包名是“com.google.android.apps.walletnfcrel”。这样您就可以调用问题中的方法来检测是否安装了Android Pay。
在 Kotlin 上:
private fun isAppInstalled(packageName: String): Boolean {
return try {
activity?.packageManager?.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
}
有这段代码(取自):
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;
}
但我不知道在 packageName 中放什么。我试过com.google.android.gms.wallet
(是AndroidPay使用的一些Wallet碎片的封装)但是上面的方法returns false.
原来需要的包名是“com.google.android.apps.walletnfcrel”。这样您就可以调用问题中的方法来检测是否安装了Android Pay。
在 Kotlin 上:
private fun isAppInstalled(packageName: String): Boolean {
return try {
activity?.packageManager?.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
}