我需要打开我的.doc文件在quickoffice在我的应用程序,而不是寻找合适的应用程序(选项)。
我用过这个
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))));这个代码显示了我实际上不需要的合适的目标应用程序
发布于 2014-06-16 13:12:09
对我起作用了。
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);发布于 2014-06-14 07:43:01
删除createChooser调用,然后将意图传递给startActivity。然后它将打开mime类型的默认应用程序,前提是设置了一个。如果没有设置,它可能仍然会在那些声称可以打开它的应用程序中弹出一个选择器。如果您只想打开快速办公室,您可以通过活动名称来打开它,但是如果没有安装快速办公室,它就会失败(并可能引发异常)。
https://stackoverflow.com/questions/24217713
复制相似问题