'Get all the activities/packagename/apps name which are displayed in chooser intent

I want to get list of all the activities that can handle UPI intent. OR I want to get list of all activities that are displayed in Chooser intent for a upi intent.

e.g google pay, amazon pay, paytm etc

wallet apps image

    void payUsingUpi() {

        Uri uri = Uri.parse("upi://pay").buildUpon().build();
        
        Intent upiPayIntent = new Intent();
        upiPayIntent.setAction(Intent.ACTION_VIEW);

        upiPayIntent.setData(uri);

        Intent chooser = Intent.createChooser(upiPayIntent, "Pay with");
        
        // check if intent resolves
        if (chooser.resolveActivity(getPackageManager()) != null) {
            activityLauncherForUpiPayements.launch(chooser);
        } else {
            Toast.makeText(this, "No UPI app found, please install one to continue", Toast.LENGTH_SHORT).show();
        }

    }

ActivityResultLauncher<Intent> activityLauncherForUpiPayements = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
        // Toast.makeText(WalletActivity.this, "returned from activty", Toast.LENGTH_SHORT).show();
        if (result.getResultCode() == Activity.RESULT_OK) {
            if (result.getData() != null) {
                String trxt = result.getData().getStringExtra("response");
                //Log.d("UPI", "onActivityResult: " + trxt);
                ArrayList<String> dataList = new ArrayList<>();
                dataList.add(trxt);
                upiPaymentDataOperation(dataList);
            } else {
                //Log.d("UPI", "onActivityResult: " + "Return data is null");
                ArrayList<String> dataList = new ArrayList<>();
                dataList.add("nothing");
                upiPaymentDataOperation(dataList);
            }
        } else {
            //Log.d("UPI", "onActivityResult: " + "Return data is null"); //when user simply back without payment
            ArrayList<String> dataList = new ArrayList<>();
            dataList.add("nothing");
            upiPaymentDataOperation(dataList);
        }
    });

I have tried below snippet provided in other Stackoverflow answer

PackageManager packageManager = getPackageManager();
List<ResolveInfo> result = packageManager.queryIntentActivities(chooser, 0);
for (ResolveInfo resolveInfo : result) {
    Toast.makeText(this, "" + resolveInfo.activityInfo.packageName, Toast.LENGTH_SHORT).show();
}

it gave output like below:

android android.system.ui.chooser

but I want to get all activities or package name or app name that were displayed in chooser pop-up.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source