Reputation: 687
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
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:
If there is no default set for the intent: info.activityInfo.name would equals to "com.android.internal.app.ResolverActivity"
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