How to get the list of installed Browser Apps in an Android 7.0 running devices programmatically?

不羁的心 提交于 2020-01-13 05:24:09

问题


Before Android 7.0 I was able to retrieve the list of installed browser type applications and it's package name. Then, I upgrade to Android 7.0 and I am only able to retrieve Samsung's Internet browser, but not the other browser type applications such as Chrome .

Device Samsung Tab A

This is the code :

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, 0);
        for (ResolveInfo info : browserList) {
            browserPackageName.add(info.activityInfo.packageName);
            Log.e("BrowserList Info ",info.activityInfo.packageName+" total browser"+browserList.size());
        }
    } catch (Exception e) {
        e.printStackTrace();
        Log.e("BrowserList Info ",e.getMessage());
    }
    return browserPackageName;
}

回答1:


If Android API level >= 23, then you can do like so:

List<ResolveInfo> browserList;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.MARSHMALLOW) {
    browserList = pm.queryIntentActivities(intent, PackageManager.MATCH_ALL);
} else {
    browserList = pm.queryIntentActivities(intent, 0);
}



回答2:


Code looks fine. However you should use PackageManager.MATCH_DEFAULT_ONLY flag -

pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)

instead of pm.queryIntentActivities(intent, 0)



来源:https://stackoverflow.com/questions/48209151/how-to-get-the-list-of-installed-browser-apps-in-an-android-7-0-running-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!