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());
}
那是我的代码,我在 Android 2.1 中没有得到 mime 类型,我在那个日志中得到了 null。
不过,我可以在 Android 2.3.3 中使用相同的代码相同的应用程序来获取它。