2

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 (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);

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?

Sparky
  • 31
  • 5
  • Have you found a solution yet? – Jules May 24 '19 at 11:38
  • Just wrote a technical documentation what I still found out: https://github.com/cryptomator/cryptomator-android/issues/150#issuecomment-514401775 Microsoft has to fix this problem as soon as possible! – Jules Jul 23 '19 at 22:13
  • No, still no luck for me yet. Your documentation was interesting. I still cannot see how those two file manager apps I listed CAN do this with word read/write. Did you look at those? – Sparky Jul 25 '19 at 11:18
  • Just rechecked, on my device (OP3T LOS version 16.0) the intent of the ASUS file manager looks like this and Word has NO write access: ` {act=android.intent.action.VIEW dat=content://com.asus.filemanager.OpenFileProvider/file/sdcard/aeq_dpunkt.doc typ=application/msword flg=0x80003 cmp=com.microsoft.office.word/.WordActivity}` oooh no, just found out, that there is a difference between .doc and .docx files. .docx has write permission in ASUS file manager. Will check my code again with this new input!!! – Jules Jul 25 '19 at 15:45

1 Answers1

0

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!

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

Jules
  • 189
  • 1
  • 5
  • 20
  • I have actually been experimenting with my own content providers. This does indeed allow a Word edit. I have another issue on top of this, and that is that I have to wrap the project for an MDM deployment, and that doesn't appear to work with a custom content provider - only the built in one! – Sparky Aug 02 '19 at 15:24
  • @Sparky with your own implementation of a content providers you can edit Word files in internal storage of the app? – Jules Aug 13 '19 at 14:49
  • It was a while back and I had tried many things ;-) I just checked, and currently it is using getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS) – Sparky Aug 27 '19 at 16:17