我需要在我的应用程序的quickoffice中打开.doc文件,而无需寻找合适的应用程序(选项)。
在这里我用了
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
//String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
// MimeTypeMap.getFileExtensionFromUrl(uri.toString()));
//intent.setDataAndType(uri, type == null ? "*/*" : type);
intent.setDataAndType(uri, "application/msword");
startActivity((Intent.createChooser(intent,
getString(R.string.open_using))));
此代码显示了我实际上不需要的合适的目标应用程序
它为我工作。
PackageManager packageManager = getPackageManager();
Intent quickOffice = packageManager
.getLaunchIntentForPackage("com.quickoffice.android");
File sdcard = Environment.getExternalStorageDirectory();
//your file location
File file = new File(sdcard, "Meta Data.doc");
Uri path = Uri.fromFile(file);
quickOffice.setAction(Intent.ACTION_VIEW);
quickOffice.setDataAndType(path, "application/msword");// ---->application/msword
startActivity(quickOffice);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句