如何在Android中打开Word文档文件?

时间:2018-07-03 12:44:29

标签: android android-webview androidpdfviewer

我在服务器中有一个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();
            }

1 个答案:

答案 0 :(得分:0)

我有此链接,该链接显示了如何在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。

相关问题