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).
The file IS read-write in other apps that can edit a docx (eg 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);
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
Has anyone else here managed to open Word documents for read AND write ok?
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. 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. Here you can find a short overview: https://github.com/cryptomator/cryptomator-android/issues/150#issuecomment-514401775
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.