繁体   English   中英

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

[英]How to open word document file in android?

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

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

另外,有一个类似的情况,这是由PDF文件完成的: Android:如何从Android中的服务器打开pdf文件

希望这些链接对您有用。

祝你好运,G。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM