给意图一个动作而不是类别,并查询可以执行的动作ACTION_VIEW
一个网址,像这样:
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);
返回的内容如下:
[ResolveInfo{44e9d350 com.android.browser.BrowserActivity p=0 o=0 m=0x208000}]
假设您安装了多个浏览器,它将包含所有浏览器。也许我误解了你的问题,但从技术上讲,这会返回与你尝试启动打开 URL 的意图时得到的应用程序相同的应用程序。
至于获取这些应用程序的启动器活动,因为您已经知道如何获取所有主要应用程序,并且根据我给出的代码(您想要的应用程序),您可以匹配包名称(大概)来找到启动器( ?)
UPDATE
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+"");
}
}
正如我所说,您从启动器获取所有包,并将它们与能够执行操作(无论是拍照还是浏览网页)的包进行匹配。你应该能够让事情顺利进行。