MMauro
MMauro

Reputation: 687

ResolveInfo.isDefault always on false

I'm trying to get the icon of the default program associated with an extension.

Here's my code:

Intent intent = new Intent(Intent.ACTION_VIEW);
MimeTypeMap mime = MimeTypeMap.getSingleton();
String tt = mime.getMimeTypeFromExtension(getExtension());

intent.setDataAndType(Uri.fromFile(getFile()), tt);

List<ResolveInfo> matches = c.getPackageManager().queryIntentActivities(intent, 0);

for (ResolveInfo match : matches) {
     if(match.isDefault){
          //GET ICON
     }
}

The problem is that match.isDefault always returns false, even if I try to set the flag of the PackageManager from 0 to PackageManager.MATCH_DEFAULT_ONLY.

Obiviously, the file I'm testing (a video) is associated by default with a program (MX Player).

Can somebody help me?

Thanks in advance.

Upvotes: 1

Views: 610

Answers (1)

EwyynTomato
EwyynTomato

Reputation: 4077

As an alternative solution, you may want to get the default intent using this method instead:

     ResolveInfo info = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);

The returned result would be the:

  1. If there is no default set for the intent: info.activityInfo.name would equals to "com.android.internal.app.ResolverActivity"

  2. If there is any default app set for the intent, then you may check on the ResolveInfo object for the default app infomation.

Edit:

For url, you can do something like this:

    //Example: youtube url
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=something"));
    ResolveInfo defaultResolution = getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);

    //Print the activity name
    Log.i(TAG, "defaultResolution:" + defaultResolution.activityInfo.name);

Upvotes: 3

Related Questions