如何在 Android 上使用 Intent 打开 Word 文档作为可编辑文件? [英] How do I open a Word Document as an Editable file using an Intent on Android?

查看:91
本文介绍了如何在 Android 上使用 Intent 打开 Word 文档作为可编辑文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Intent 在 Android 上的 Word 中打开一个 docx 文件,但它总是打开只读(Word 提示说它是只读的).

I'm trying to open a docx file in Word on Android using an Intent, but it always opens Read Only (Word prompts to say it is read only).

该文件在可以编辑 docx 的其他应用程序中是可读写的(例如 WPS Office).只有 Microsoft Word 是问题所在.

The file IS read-write in other apps that can edit a docx (e.g. WPS Office). Only Microsoft Word is the issue.

        String fileUrl = "/storage/emulated/0/Download/test.docx";
    File file = new File(fileUrl);
    String mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";

    Uri theUri = FileProvider.getUriForFile(this,
                "com.example.testint.fileprovider",
                file);
    Intent intent = new Intent();

    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    intent.setDataAndType(theUri, mime);

    startActivity(intent);

我已经使用其他几个应用程序运行了意图拦截.华硕文件管理器和 ASTRO 文件管理器和文件管理器 1.36 都能够使用 content://以读/写方式打开 Word 文档,并且没有只读问题.意图看起来与我的意图相同,所以我看不出它们是如何工作的,如果不这样做.

I have run an Intent Intercept with several other apps. ASUS File Manager and ASTRO file manager and File Manager 1.36 are all able to open Word documents as Read/Write using content:// and do not have the read only issue. The intents look the same as my intent, so I cannot see how they can work, when this does not.

这是来自华硕文件管理器:

This is from ASUS file manager:

    intent://com.asus.filemanager.OpenFileProvider/file/sdcard/Documents/Test.docx#Intent;scheme=content;type=application/vnd.openxmlformats-officedocument.wordprocessingml.document;launchFlags=0x3000000;end 
------------ 
ACTION: android.intent.action.VIEW 
DATA: content://com.asus.filemanager.OpenFileProvider/file/sdcard/Documents/Test.docx 
MIME: application/vnd.openxmlformats-officedocument.wordprocessingml.document 
URI: intent://com.asus.filemanager.OpenFileProvider/file/sdcard/Documents/Test.docx#Intent;scheme=content;type=application/vnd.openxmlformats-officedocument.wordprocessingml.document;launchFlags=0x3000000;end 
FLAGS: 
FLAG_ACTIVITY_FORWARD_RESULT 
FLAG_ACTIVITY_PREVIOUS_IS_TOP 

这里有没有其他人设法打开 Word 文档进行读写正常?

Has anyone else here managed to open Word documents for read AND write ok?

推荐答案

您可以使用旧文件格式,例如file:///storage/emulated/0/Android/data/.../hello.docx 或内容提供者,例如content://org.cryptomator.fileprovider/external_files/Android/data/org.cryptomator/cache/decrypted/hallo.docx 但该文件不允许在应用程序的内部存储中.然后文件是可写的!

You can use the old file format e.g. file:///storage/emulated/0/Android/data/.../hello.docx or a content provider e.g. content://org.cryptomator.fileprovider/external_files/Android/data/org.cryptomator/cache/decrypted/hallo.docx BUT the file is not allowed to be in the app's internal storage. Then the files are writable!

带有例如的文件.doc 扩展名不可写或位于内部存储中的文件也不可写.在这里你可以找到一个简短的概述:https://github.com/cryptomator/cryptomator-android/issues/150#issuecomment-514401775

Files with e.g. the .doc extension aren't writable or files located in internal storage aren't writable as well. Here you can find a short overview: https://github.com/cryptomator/cryptomator-android/issues/150#issuecomment-514401775

这篇关于如何在 Android 上使用 Intent 打开 Word 文档作为可编辑文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆