String filename = Environment.getExternalStorageDirectory()+"/word.docx";
try{
File file = new File(filename);
Uri path = Uri.fromFile(file);
Intent viewDoc = new Intent(Intent.ACTION_VIEW);
Log.i(TAG, "mime type "+URLConnection.guessContentTypeFromName(filename).toString());
viewDoc.setDataAndType(path, URLConnection.guessContentTypeFromName(filename));
PackageManager pm = getPackageManager();
List<ResolveInfo> apps =
pm.queryIntentActivities(viewDoc, PackageManager.MATCH_DEFAULT_ONLY);
if (apps.size() > 0){
startActivity(viewDoc);
}
}catch(Exception e){
Log.i(TAG, "oh exception "+e.getMessage());
}
That is my code and I'm not getting the mime type in Android 2.1, I get null in that Log.
Though, I'll able to get it in the Android 2.3.3 with the same code same app.