0

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Amit Yadav
  • 32,664
  • 6
  • 42
  • 57
  • 1
    You should mention packages in queries. Package visibility – blackapps Sep 26 '21 at 10:07
  • @blackapps can u please explain it in detail. – Amit Yadav Sep 26 '21 at 10:37
  • The simplest answer has always been to just wrap the `startActivityForResult()` call in a `try`/`catch` block and handle the exception. Not only does that handle missing activities but is also handles any other problems that might crop up. Beyond that, I think that your `resolveActivity()` and `` should be for set up for the `ACTION_VIEW` `Intent`, not the chooser `Intent`. Or, if you *really* want to use `resolveActivity()` for the chooser itself, remove the `` element, as the chooser `Intent` has no scheme. – CommonsWare Sep 27 '21 at 10:42
  • @Amit yadav solution – Jithish P N Jul 01 '22 at 09:52
  • @JithishPN Sorry, I don't have any solution for it. – Amit Yadav Jul 01 '22 at 10:46

1 Answers1

0

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

Jithish P N
  • 1,970
  • 3
  • 26
  • 39