【问题标题】:programmatically detect whether a Browser is installed on Android以编程方式检测 Android 上是否安装了浏览器
【发布时间】:2018-12-24 16:41:36
【问题描述】:

如何检查安卓设备上是否安装了浏览器

我需要检查设备上是否安装了浏览器。我们该怎么做

【问题讨论】:

标签: android browser


【解决方案1】:

你可以试试这个。

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

【讨论】:

    【解决方案2】:

    您可以检查是否可以解决访问网页的意图:

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

    【讨论】:

      【解决方案3】:

      您可以尝试检查系统是否处理协议,例如:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-17
        • 1970-01-01
        • 2018-12-28
        • 2010-09-22
        相关资源
        最近更新 更多