Android的抓取安装和设备的默认浏览器 [英] Android Fetch installed and default browser in device

查看:144
本文介绍了Android的抓取安装和设备的默认浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够得到所有这些都是启动的帮助下 Intent.CATEGORY_LAUNCHER 的应用程序。

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

因此​​,对于测试我创建的测试活动,该活动包含一个按钮,如果我preSS按钮时,它应该显示在设备中的应用程序

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.`

我这样尝试了小code:

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.

推荐答案

而不是一个品类,给意图的动作和查询那些能 ACTION_VIEW 一个URL,像这样:

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

和假设你安装多个浏览器,它将包含所有这些。也许我误解你的问题,但这种技术上返回,如果你试图启动意图打开URL你会得到相同的应用程序。

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.

至于让这些应用程序的发射活动,因为你已经知道如何获得所有主要的应用程序和由code我给,你后的人,你可以匹配的包名(assumably)找到启动一(?)

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 (?)

更新

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.

这篇关于Android的抓取安装和设备的默认浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆