4

我正在寻找一种方法来在设备中搜索所有能够通过操作“VIEW”和类别“BROWSABLE”过滤意图的应用程序?

我找到了以下链接并学习了如何列出所有 Intent 过滤器,但是如何仅列出仅具有上述参数的那些?

http://developer.android.com/reference/android/content/pm/PackageManager.html#queryIntentActivities%28android.content.Intent,%20int%29

获取接收者的意图过滤器

如何过滤 ACTION_SEND 意图的特定应用程序(并为每个应用程序设置不同的文本)

提前致谢

4

1 回答 1

12

这段代码应该或多或少地做你想要的。主要问题是,我认为您不会找到任何过滤活动CATEGORY_BROWSABLE而不需要特定类型的数据。我在手机上试过了,直到我setData()在 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);
        }
    }
}
于 2012-08-01T15:19:02.750 回答