Android: How to get the right application name?

719 Views Asked by At

Currently I have written a code to load all capable applications which can view images from the phone.

public static List<String> getAllCapableForFileViewing (Context context, String mimeType) {
    List<String> packages = new ArrayList<>();
    PackageManager pm = context.getPackageManager();
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_VIEW);
    sendIntent.setType(mimeType);
    List<ResolveInfo> resolveInfoList = context.getPackageManager()
            .queryIntentActivities(sendIntent, 0);

    for (ResolveInfo resolveInfo : resolveInfoList) {
        packages.add(resolveInfo.activityInfo.packageName);

        System.out.println(resolveInfo.activityInfo.packageName);
        System.out.println(resolveInfo.activityInfo.applicationInfo.className);
        System.out.println(resolveInfo.activityInfo.name);
        System.out.println("");
    }

    return packages;
}

When I tried to list all the applications, one of them have two set listed e.g. WeChat, WeChat Moment. Obviously it have two activities which can handle the image for viewing. The problem is the name of the two are the same "WeChat".

Additionally? even though it can consume the content i passed in but they are not really application for viewing images e.g. Gallery application. Is there a way to recognise them. I know it may be impossible.

1

There are 1 best solutions below

4
On BEST ANSWER

The problem is the name of the two are the same "WeChat".

Well, in the end, that is up to the developers of that app. However, look at labelRes of the ResolveInfo, as this may be a better label to use (e.g., pulled from the <intent-filter>).

Is there a way to recognise them

You are welcome to try using CATEGORY_APP_GALLERY, though this may lead to false negatives (i.e., apps that the user would expect to show up that do not).