SDKLess PhonePe Intent
Method to check whether the PhonePe UPI app is installed on the android device:
private boolean isUpiRegistered() {
String phonepePackageName = "com.phonepe.app";
//For PreProd app, "com.phonepe.app.preprod"
//For Production app, "com.phonepe.app"
Uri uri = Uri.parse(String.format("%s://%s", "upi", "pay"));
Intent upiUriIntent = new Intent();
upiUriIntent.setData(uri);
PackageManager packageManager = getApplication().getPackageManager();
List < ResolveInfo > resolveInfoList = packageManager.queryIntentActivities(upiUriIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfoList != null) {
for (ResolveInfo resolveInfo: resolveInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
if (packageName != null && !packageName.isEmpty() && phonepePackageName.matches(packageName)) {
return true;
}
}
}
return false;
}
SDKLess Open Intent
Method to get the list of all the UPI apps installed on the android device:
private ArrayList < String > getInstalledUPIApps() {
ArrayList < String > upiList = new ArrayList < > ();
Uri uri = Uri.parse(String.format("%s://%s", "upi", "pay"));
Intent upiUriIntent = new Intent();
upiUriIntent.setData(uri);
PackageManager packageManager = getApplication().getPackageManager();
List < ResolveInfo > resolveInfoList = packageManager.queryIntentActivities(upiUriIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfoList != null) {
for (ResolveInfo resolveInfo: resolveInfoList) {
upiList.add(resolveInfo.activityInfo.packageName);
}
}
return upiList;
}