Android intent.resolveActivity returns null in API 30

1.7k Views Asked by At

In our app we have payment gateway implementation. We are opening intent to open GPay, PhonePay, Paytm and other apps. Please find the below code snipped,

String url = "upi://pay?pa=fcbizpayg@freecharge&pn=PAYG&mc=7299&tid=AXIFRCO1506202118501b5bu4s903cafgu4&tr=AXIFRCO1506202118501b5bu4s903cafgu4&am=50.00&cu=INR";

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(url);

Intent appChooser = Intent.createChooser(intent, "Pay using");

if (intent.resolveActivity(getPackageManager()) != null) {
     startActivityForResult(appChooser, PAYMENT_REQUEST);
} else {
     Toast.makeText(PaymeroUserDetailsActivity.this, "No UPI app found! Please Install to Proceed!", Toast.LENGTH_LONG).show();
}

I added "queries" tag in AndroidManifest.xml

<queries>
    <intent>
        <action android:name="android.intent.action.CHOOSER" />
        <data android:scheme="upi" />
    </intent>
</queries>

Even though UPI apps are installed on device but we are getting No UPI app found! Please Install to Proceed!

Please assist me what I do.

1

There are 1 best solutions below

0
On

From Android 11 - There is a new restriction on package visibility using package manager. getPackageManager().resolveActivity().

due to this return as null

Solution :

Queries has to be added into your manifest.

Example:

<queries>
    <!--for WebView -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" />
    </intent>
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https" />
    </intent>

Refer : https://developer.android.com/about/versions/11/privacy/package-visibility

https://developer.android.com/training/package-visibility/use-cases