如何检查浏览器是否已安装在Android设备上
我需要检查设备上是否安装了浏览器。我们该怎么做
答案 0 :(得分:1)
您可以检查进入网页的意图是否可以解决:
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);
}
答案 1 :(得分:0)
您可以尝试一下。
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 :(得分:0)
您可以尝试检查系统是否处理了以下协议:
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;
}