Hi,
How would i be able to get the mimeType from an application.
I am working on an application which filters certain installed applications based on the mimeType.
could someone please help me with this issue ?
thanks alot
Hi,
How would i be able to get the mimeType from an application.
I am working on an application which filters certain installed applications based on the mimeType.
could someone please help me with this issue ?
thanks alot
How would i be able to get the mimeType from an application.
Applications do not have MIME types.
You can create an ACTION_VIEW
Intent
with some MIME type and use PackageManager
and queryIntentActivities()
to identify which activities will respond to that Intent
.
You can only get MIME type of data in intent:
String type = getIntent().getType();
mime types are associated with activities. You can use List and PackageManager.queryIntentActivities(i, 0) to get all the activities and therefore applications for a given data mime type.
public static List<ResolveInfo> getIntents(String action, String category,
PackageManager pm) {
Intent i = new Intent(action, null);
i.addCategory(category);
i.setData(data_uri)
List<ResolveInfo> list = pm.queryIntentActivities(i, 0);
return list;
}
Else, you can get all applications (Launchable) by:
getIntents(Intent.ACTION_DEFAULT,Intent.CATEGORY_LAUNCHER,pm);
and now classify by String type = getIntent().getType();
Hi, i wrote a code like this , but am getting null for type:
PackageManager pm = getPackageManager(); String pkgName ="com.android.mms"; Intent intent = pm.getLaunchIntentForPackage(pkgName); String type =intent.getType();
Can someone please help me?
While this is not a complete answer, this should help you get closer:
PackageManager pm = getPackageManager();
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
//i.setData(Media.INTERNAL_CONTENT_URI);
List<ResolveInfo> list = pm.queryIntentActivities(i, 0);
for(ResolveInfo item : list){
try {
PackageInfo info = pm.getPackageInfo(item.activityInfo.applicationInfo.packageName, pm.GET_SIGNATURES);
Signature[] s = info.signatures;
Log.d(LOG_TAG,item.activityInfo.name +":"+ s.toString());
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(item.filter!=null){
Log.d(LOG_TAG,item.activityInfo.name + ": " + item.filter.toString());
List<String> types = (List<String>) item.filter.typesIterator();
}
}