How to get default applications set by users in android through code? I know we can get the default application's package name through packageManager for a particular MIME type. But is there a way to get a list of all the applications registered as default for opening various files?

有帮助吗?

解决方案

Use PackageManager.getPreferredActivities()

    final PackageManager pm = getActivity().getPackageManager();

    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_LAUNCHER);

    List<IntentFilter> outFilters = new ArrayList<IntentFilter>();
    outFilters.add(filter);

    List<ComponentName> outActivities = new ArrayList<ComponentName>();
    pm.getPreferredActivities(outFilters, outActivities, null);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top