[英]How do I open a Word Document as an Editable file using an Intent on Android?
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). 我正在尝试使用Intent在Android上的Word中打开docx文件,但它始终会打开“只读”(Word会提示说它是只读的)。
The file IS read-write in other apps that can edit a docx (eg WPS Office). 该文件在其他可以编辑docx的应用程序中是读写的(例如WPS Office)。 Only Microsoft Word is the issue. 问题只有Microsoft Word。
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);
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. ASUS文件管理器和ASTRO文件管理器以及文件管理器1.36都能够使用content://以读/写方式打开Word文档,并且没有只读问题。 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
Has anyone else here managed to open Word documents for read AND write ok? 这里是否还有其他人设法打开Word文档进行读写?
You can use the old file format eg file:///storage/emulated/0/Android/data/.../hello.docx
or a content provider eg 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. 您可以使用旧文件格式,例如file:///storage/emulated/0/Android/data/.../hello.docx
或内容提供商,例如content://org.cryptomator.fileprovider/external_files/Android/data/org.cryptomator/cache/decrypted/hallo.docx
但该文件不允许位于应用程序的内部存储中。 Then the files are writable! 然后文件是可写的!
Files with eg the .doc
extension aren't writable or files located in internal storage aren't writable as well. 带有.doc
扩展名的文件不可写,或者位于内部存储中的文件也不可写。 Here you can find a short overview: https://github.com/cryptomator/cryptomator-android/issues/150#issuecomment-514401775 在这里您可以找到简短的概述: https : //github.com/cryptomator/cryptomator-android/issues/150#issuecomment-514401775
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.