阅读Android中不适用于docx的任何文件

时间:2016-08-19 11:28:29

标签: android

我正在创建一个应该能够接收和读取任何文件的应用程序。这是迄今为止的代码。

 documentViewHolder.preview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    File document = new File(Environment.getExternalStorageDirectory() + "/heyJudeDocuments/" + getItem(position).attachment_id);  // -> filename = maven.pdf
                    Uri path = Uri.fromFile(document);
                    Intent docIntent = new Intent(Intent.ACTION_VIEW);
                    docIntent.setDataAndType(path, getItem(position).mime);
                    docIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                    try {
                        activity.startActivity(docIntent);
                    } catch (ActivityNotFoundException e) {
                        Toast.makeText(activity, "No Application available to view Document", Toast.LENGTH_SHORT).show();
                    }


                }
            });

这对于pdf和ICS文件非常有效,但对于docx,我得到了意想不到的结果。该应用程序打开单词,但后来我收到错误“无法打开文件”。如果我给自己发送同一个文件并从gmail打开它就可以了。有什么想法吗?

0 个答案:

没有答案