2

I am trying to show a app chooser dialog using Intent.createChooser, that will list all available web browsers in user's phone. I'm using the code below:

        Intent browserIntent = new Intent(Intent.ACTION_VIEW);
        browserIntent.setData(Uri.parse(category));
        // Create and start the chooser
        Intent chooser = Intent.createChooser(browserIntent, "Open with...");

        pIntent = PendingIntent.getActivity(helperMethodContext, 0, chooser, PendingIntent.FLAG_UPDATE_CURRENT);

        Log.d("HelperMethods: ", "video chat url: " + category);  

I am testing this on android 6. My phone has 3 browsers, default browser, chrome and firefox. When i run it and click on the link(the notification), app chooser dialog opens but only shows default browser. It doesn't show chrome or firefox.

app chooser dialog after clicking on link in notification

I have checked default apps settings in my phone and there is no default browser. When i click default browser it opens with an app chooser dialog showing all the browser apps i have installed on my phone.

Pls can someone tell me where am i going wrong.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sissyphus_69
  • 350
  • 5
  • 18
  • @JaydeepPatel i don't want to open default browser when the link is clicked. I want to show the app chooser dialog with a list of all the installed browsers – sissyphus_69 Mar 16 '17 at 08:18
  • this might be helps you: http://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application – Jaydeep Devda Mar 16 '17 at 09:29
  • @JaydeepPatel I don't have default browser set in default apps settings. pls read the question completely. – sissyphus_69 Mar 16 '17 at 09:30

2 Answers2

0

There is so important what type of uri do you have. Is it http, https or other scheme. In your case it's Uri.parse(category). For example firefox can handle scheme like: http, https, file, about, javascript, package. And also data with mimeType: text/html, text/plain and application/xhtml+xml.

Djek-Grif
  • 1,391
  • 18
  • 18
0

Maybe this will help:

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;
}

Make ur own UI to show the app list and get list like this:

List<ResolveInfo> queries = queryIntentActivities(getPackageManager(), new Intent()...);
DiLDoST
  • 335
  • 3
  • 12