Is there any way to query an specific type of Intent Filter capable apps?

前端 未结 1 1888
灰色年华
灰色年华 2020-12-28 11:22

I\'m looking for a way to search in the device all the apps which are capable to filter Intents with action \"VIEW\" and category \"BROWSABLE\"?

I found the followin

相关标签:
1条回答
  • 2020-12-28 11:50

    This code should do more or less what you want. The main problem is that I don't think you will find any activity that filters for CATEGORY_BROWSABLE without also requiring data of a specific type. I tried it on my phone and I didn't get anything useful until I added the setData() call on the Intent.

        PackageManager manager = getPackageManager();
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        // NOTE: Provide some data to help the Intent resolver
        intent.setData(Uri.parse("http://www.google.com"));
        // Query for all activities that match my filter and request that the filter used
        //  to match is returned in the ResolveInfo
        List<ResolveInfo> infos = manager.queryIntentActivities (intent,
                                       PackageManager.GET_RESOLVED_FILTER);
        for (ResolveInfo info : infos) {
            ActivityInfo activityInfo = info.activityInfo;
            IntentFilter filter = info.filter;
            if (filter != null && filter.hasAction(Intent.ACTION_VIEW) &&
                      filter.hasCategory(Intent.CATEGORY_BROWSABLE)) {
                // This activity resolves my Intent with the filter I'm looking for
                String activityPackageName = activityInfo.packageName;
                String activityName = activityInfo.name;
                System.out.println("Activity "+activityPackageName + "/" + activityName);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题