Android Fetch installed and default browser in device
Asked Answered
R

3

5

I am able to get all the applications which are in Launcher with the help of Intent.CATEGORY_LAUNCHER.

So for testing I created a test activity, this activity contains a single button, if I press the button, it should display the applications in the device

NOTE: `it should not display specific. for example i needed only Browser it should display all browser applications.`

I tried in this way a small CODE:

btn.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_APP_BROWSER);

            List<ResolveInfo> mainLauncherList = getPackageManager().queryIntentActivities(intent, 0);
            System.out.println("the list iss = " +mainLauncherList);
        }
    });

The list is returning only one browser that is single Browser.

Romaine answered 9/5, 2012 at 8:40 Comment(0)
B
7

Instead of a category, give the intent an action and query the ones that could ACTION_VIEW a url, like so:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));

List<ResolveInfo> mainLauncherList = getPackageManager().queryIntentActivities(intent, 0);
Log.e("Browsers","the list iss = " +mainLauncherList);

Which returns something like:

[ResolveInfo{44e9d350 com.android.browser.BrowserActivity p=0 o=0 m=0x208000}]

And assuming you have more than one browser installed, it will contain them all. Maybe I misunderstood your question but this technically returns the same applications you'd get if you tried launching the intent to open the url.

As to getting the launcher activity of those applications, since you already know how to get all the main applications and by the code I gave, the one you're after, you could match the package names (assumably) to find the launcher one (?)

UPDATE

ArrayList<String> allLaunchers = new ArrayList<String>();

Intent allApps = new Intent(Intent.ACTION_MAIN);
List<ResolveInfo> allAppList = getPackageManager().queryIntentActivities(allApps, 0);
for(int i =0;i<allAppList.size();i++) allLaunchers.add(allAppList.get(i).activityInfo.packageName);

Intent myApps = new Intent(Intent.ACTION_VIEW);
       myApps.setData(Uri.parse("http://www.google.es"));
List<ResolveInfo> myAppList = getPackageManager().queryIntentActivities(myApps, 0);
for(int i =0;i<myAppList.size();i++){
    if(allLaunchers.contains(myAppList.get(i).activityInfo.packageName)){
        Log.e("match",myAppList.get(i).activityInfo.packageName+"");
    }
}

As I was saying, you get all packages, from the launcher and match them against the packages from the ones that are able to perform the action, be it take a photo, or browse the web. You should be able to get that thing going with this.

Brittnybritton answered 9/5, 2012 at 9:3 Comment(6)
Ya thank u mayhem , u said is right its is working for me but i am planning to make a custom launcher app in this if user selects browser option, exactly side by of it i will get the options like Mozilla, Opera, Dolphin which are installed from the market.Romaine
hi this is working for me for browser base app, in the same way I want to get info like How many cameras/message app install on my device, that can be default+third party app. please suggest me if have any idea for this.Romaine
@Romaine , it's as easy as replacing your filter intent's action to Intent myApps = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); and remove the setData line. I'm sure you can figure out the rest of those, by doing a little research. Please +1 the answer ^Deadhead
Is there a way to get from package name browser bookmarks uri?Agonizing
and it is returning 748 allLaunchers sizesAerate
Considering it's almost 10 years old, perhaps look for a less outdated answerDeadhead
M
6

Above API version 30, I needed to add a queries section to AndroidManifest.xml, due to new package visibility rules (in addition to using PackageManager.MATCH_ALL as mentioned above).

<manifest ...>
    <application ... />
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="http" />
        </intent>
    </queries>
</manifest>
Matlock answered 22/1, 2021 at 20:9 Comment(0)
R
1

If anyone else needed the answer:

public static void getBrowserApps(Context mcontext) {
        PackageManager packageManager = mcontext.getPackageManager();
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("http://www.google.com"));
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent,
        PackageManager.MATCH_ALL);}

list will contain package information of all browser.

Relentless answered 5/2, 2018 at 5:59 Comment(1)
This solution covers important flag (PackageManager.MATCH_ALL). Otherwise only default browser is returned.Package

© 2022 - 2024 — McMap. All rights reserved.