0

我在服务器中有一个 word 文档(.doc.docx)。我需要通过单击一个按钮在我的 android 应用程序中打开 .doc 文件必须打开。这个怎么做?任何人,请帮助我。

我试过这段代码:

File file = new File(Environment.getExternalStorageDirectory(),
                    "Document.docx");
            try {
                if (file.exists()) {
                    Uri path = Uri.fromFile(file);
                    Intent objIntent = new Intent(Intent.ACTION_VIEW);
                    // replace "application/msword" with
                    // "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
                    // for docx files
                    // objIntent.setDataAndType(path,"application/msword");
                    objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(objIntent);
                } else {
                    Toast.makeText(PMComplitionProjectActivity.this, "File NotFound",
                            Toast.LENGTH_SHORT).show();
                }
            } catch (ActivityNotFoundException e) {
                Toast.makeText(PMComplitionProjectActivity.this,
                        "No Viewer Application Found", Toast.LENGTH_SHORT)
                        .show();
            } catch (Exception e) {
                e.printStackTrace();
            }
4

1 回答 1

1

我有这个链接显示如何在 Android 中打开任何文件:http ://www.androidsnippets.com/open-any-type-of-file-with-default-intent.html

此外,还有一个类似的案例,由 PDF 文件完成:Android : how to open pdf file from server in android

我希望这些链接对你有用。

祝你好运,G。

于 2018-07-03T12:59:41.497 回答