将我的意图发送给app选择器以打开ms word doc

时间:2016-10-13 19:47:58

标签: android android-studio ms-word doc opendocument

请看下面这段代码,因为你可以看到我的FilePath只获得这条路径 / document / 1393 ,所以我如何得到像 /sdcard/document/test.docx这样的绝对路径

vendor-bundle

1 个答案:

答案 0 :(得分:0)

试试这个:

Uri uri = Uri.fromFile(new File("/path/to/file"));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// Verify that there are applications registered to handle this intent
// (resolveActivity returns null if none are registered)
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(intent);
}

根据您(在活动,视图,片段中)执行此代码的位置,您可能需要将getPackageManager()调整为getActivity().getPackageManager()getContext().getPackageManager()