3

how to check whether browser is installed on android device

I need to check whether browser is installed on a device or not.how can we do that

1234567
  • 2,226
  • 4
  • 24
  • 69
  • https://stackoverflow.com/questions/23611548/how-to-find-default-browser-set-on-android-device – AskNilesh Jul 17 '18 at 05:09
  • Possible duplicate of [Check if application is installed - Android](https://stackoverflow.com/questions/18752202/check-if-application-is-installed-android) – Mr. Roshan Jul 17 '18 at 05:09
  • I dont want to know which app is installed, I want to know if any browser is installed, its like we do to find out if an email client is present – 1234567 Jul 17 '18 at 05:10
  • 1
    Check to see if there's an app that will VIEW text/html? – Gabe Sechan Jul 17 '18 at 05:28

3 Answers3

7

You can check whether an intent to go to a web page can be resolved:

public Boolean isBrowserInstalled() {
    String url = "https://stackoverflow.com";
    Uri webAddress = Uri.parse(url);
    Intent intentWeb = new Intent(Intent.ACTION_VIEW, webAddress);
    return (intentWeb.resolveActivity(getPackageManager()) != null);
}
0

You can try this.

public static List<String> getListOfBrowser(Context context) {
        List<String> browserPackageName = new ArrayList<String>();
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("http://www.google.com"));
            PackageManager pm = context.getPackageManager();
            List<ResolveInfo> browserList = pm.queryIntentActivities(intent, PackageManager.MATCH_ALL);
            for (ResolveInfo info : browserList) {
                browserPackageName.add(info.activityInfo.packageName);
            }
            Log.e("list",browserPackageName.toString());
            Log.e("size",browserList.size()+"");
            if (browserList.size()==0)
                Log.e("browser installed","No");
            else
                Log.e("browser installed","Yes " + "Total Browsers = " + browserList.size());

        } catch (Exception e) {
            e.printStackTrace();
            Log.e("BrowserList Info ",e.getMessage());
        }
        return browserPackageName;
    }
khushbu vadi
  • 391
  • 2
  • 10
0

You could try to check is system handles protocols like:

public boolean isDefaultBrowserForHttp() {
  return getDefaultProtocolHandler("http://") != null && !"com.google.android.setupwizard".equalsIgnoreCase(getDefaultProtocolHandler("http://").packageName)
}

public static ActivityInfo getDefaultProtocolHandler(String protocolName) {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(protocolName));
        ResolveInfo resolveInfo = App.getInstance().getPackageManager().resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
        if (resolveInfo != null) {
            if (resolveInfo.activityInfo != null) {
                return resolveInfo.activityInfo;
            } else {
                Logger.d("We can't get activityInfo about default browser on device", LogModule.CONFIGS);
            }
        } else {
            Logger.d("We can't get resolveInfo about default browser on device", LogModule.CONFIGS);
        }
        return null;
    }
Djek-Grif
  • 1,391
  • 18
  • 18