[英]How to load only upi apps installed in device in android studio
我嘗試使用查詢包還在清單中添加了意圖過濾器,但所有應用程序都顯示我只需要 upi 應用程序
請重新考慮付款架構。 我將合並您正在使用的付款 API,然后讓它處理付款,而不是手動查找設備上安裝的應用程序。
沒有直接的方法可以找到所有支付應用程序。 盡管如此,如果您想通過這條路線使用 go,您可以維護所有支付應用程序的詳盡列表,並檢查設備上安裝了哪些應用程序。 在這里,您將不得不不斷更新和維護支付應用程序列表。
試試下面的代碼。
packageManager = context.getPackageManager();
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_DEFAULT);
mainIntent.addCategory(Intent.CATEGORY_BROWSABLE);
mainIntent.setAction(Intent.ACTION_VIEW);
Uri uri1 = new Uri.Builder().scheme("upi").authority("pay").build();
mainIntent.setData(uri1);
final List pkgAppsList =
context.getPackageManager().queryIntentActivities(mainIntent, 0);
for (int i = 0; i < pkgAppsList.size(); i++) {
ResolveInfo resolveInfo = (ResolveInfo) pkgAppsList.get(i);
Log.d("TAG", "packageName: " + resolveInfo.activityInfo.packageName);
Log.d("TAG", "AppName: " + resolveInfo.loadLabel(packageManager));
Log.d("TAG", "AppIcon: " +resolveInfo.loadIcon(packageManager));
}
. 如果您的應用程序以 Android 11(API 級別 30)或更高版本為目標,系統會自動使某些應用程序對您的應用程序可見,但默認情況下會隱藏其他應用程序。 因此,要在 OS 11 及更高版本上工作,請包括如下的“查詢”元素。
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="pay"
android:scheme="upi" />
</intent>
</queries>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.