3

I'm creating and ACTION_VIEW intent with a URI like https://www.example.com/somedirection.

There's an app, lets call it the EXAMPLEAPP than can open that intent, but if you do not have that app in your phone. Then you can open the URI in any browser.

The thing is that I don't want the user to use the EXAMPLEAPP to follow that intent because I'm having some problems when the user returns to my app (they have to make a payment in that intent).

So, if the user doesn't have the app, no problem, everything good. But if the user have the EXAMPLEAPP the intent chooser only shows that app, it doesn't show any browser, but, as I said, I don't want the user to complete the intent with that app.

Why is the chooser not showing any browser (I have Chrome installed) and only the app when the app is installed?

This is my code.

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(electronicLink));
Intent chooser = Intent.createChooser(intent, "Some title");
if (intent.resolveActivity(packageManager) != null) {
    context.startActivity(chooser);
}

I have also tried to call

List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0);

And I'm only seeing the app when it's installed and Chrome when it's not.

Gustavo Conde
  • 927
  • 12
  • 20
  • Were you able to solve this issue? I am having a similar issue, http://stackoverflow.com/questions/42826332/intent-createchooser-for-action-view-shows-default-browser-only – sissyphus_69 Mar 16 '17 at 06:12
  • 1
    No. Something has been changed from Android 5 to Android 6. In a phone with Android 5 I have the browser option besides the app option. In a phone with Android 6 I can only open the link with the app. – Gustavo Conde Mar 16 '17 at 13:58
  • I am on API 23. I am also having the same problem. Previously, Chrome, Google pdf viewer and ES Downloader was shown in my app list but now ES Downloader and Google pdf viewer are displayed although chrome, opera mini are also installed. @GustavoConde have you solved this? – Sagar Chapagain Jul 04 '17 at 09:51
  • I found the solution. The problem was in OS. I am using Samsung J5. All the applications were shown after Resetting app preferences from Settings->App Manager. – Sagar Chapagain Jul 04 '17 at 11:27

1 Answers1

0

Yeah i found same issue with my Android 11. Working fine on my Pie but not so. Therefore i created my own code to get queries:

private static List<ResolveInfo> queryIntentActivities(PackageManager pm,Intent in) {
    ArrayList<ResolveInfo> queries=new ArrayList<>();
    {
        // get default queries
        List<ResolveInfo> i=pm.queryIntentActivities(in, 0);
        if(i!=null){
            queries.addAll(i);
        }
    }
    // check if package name already not set
    if(Utils.isEmpty(in.getPackage())){

        // search all installed apps for custom query
        for(ApplicationInfo ai:pm.getInstalledApplications(0)){

            // clone and change package name
            Intent intent=in.cloneFilter().setPackage(ai.packageName);

            // get queries of current package with intent
            List<ResolveInfo> i=pm.queryIntentActivities(intent, 0);

            // check if the app has queries for the intent
            if (i != null) {

                // add all queries to the list
                for(ResolveInfo ri:i){

                    // check for duplicate entries
                    if(!queries.contains(ri)){
                        queries.add(ri);
                    }
                }
            }
        }
    }
    return queries;
}

Hope it works ;-)

DiLDoST
  • 335
  • 3
  • 12