繁体   English   中英

如何在Android上使用Intent打开Word文档作为可编辑文件?

[英]How do I open a Word Document as an Editable file using an Intent on Android?

我正在尝试使用Intent在Android上的Word中打开docx文件,但它始终会打开“只读”(Word会提示说它是只读的)。

该文件在其他可以编辑docx的应用程序中是读写的(例如WPS Office)。 问题只有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);

我已经与其他几个应用程序进行了意图拦截。 ASUS文件管理器和ASTRO文件管理器以及文件管理器1.36都能够使用content://以读/写方式打开Word文档,并且没有只读问题。 这些意图看起来与我的意图相同,所以我看不到它们如何工作,而实际上却不行。

这是从华硕文件管理器:

    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文档进行读写?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM