Installed Android Fetch and the default browser on the device

I can get all applications located in Launcher using Intent.CATEGORY_LAUNCHER .

So, for testing, I created a test activity, this activity contains one button, if I press a button, it should display applications in the device

 NOTE: `it should not display specific. for example i needed only Browser it should display all browser applications.` 

In this way I tried 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 returns only one browser, which is the browser.

+4
source share
2 answers

Instead of a category, indicate the intention of the action and request those that could have an ACTION_VIEW URL, for example:

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

And if you have more than one browser installed, it will contain all of them. Perhaps I misunderstood your question, but this technically returns the same applications that you would get if you tried to run the intention to open the URL.

As for getting activity to run these applications, since you already know how to get all the main applications and the code I gave, the one you need, you can match the package names (presumably) to find the one (?) Launcher

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

As I said, you get all the packages from the launcher and compare them with the packages from those that are able to perform the action, whether it be a photo or web browsing. You must be able to do this.

+6
source

If anyone else needs an answer:

 public static void getBrowserApps(Context mcontext) { PackageManager packageManager = mcontext.getPackageManager(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.google.com")); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL);} 

list will contain information about the browser package.

0
source

Source: https://habr.com/ru/post/1411466/


All Articles