【问题标题】:How to open word document file in android?如何在android中打开word文档文件?
【发布时间】:2018-12-11 18:59:05
【问题描述】:

我在服务器中有一个 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 android-webview androidpdfviewer


【解决方案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.

【讨论】:

  • 我尝试了您的第一个链接代码。它显示 doc 和 pdf 文件无法打开文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-20
  • 2023-03-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多