Word 文档在使用 Intent 打开时始终为只读 [英] Word document is always Read-Only when opened with Intent

查看:52
本文介绍了Word 文档在使用 Intent 打开时始终为只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MS-Word 在我的 Xamarin.Android 应用程序中打开和编辑位于外部存储中的 word 文档这段代码:

I am trying to open and edit a word document located in my external storage in my Xamarin.Android App with MS-Word with this code:

File wordFile = new File(wordFilePath);
wordFile.SetWritable(true);

FileInfo fileInfo = new FileInfo(wordFilePath);
fileInfo.IsReadOnly = false;

Android.Net.Uri uri = FileProvider.GetUriForFile(Context, Context.PackageName + ".provider", wordFile);

Intent intent = new Intent();
intent.AddFlags(ActivityFlags.NewTask);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
intent.AddFlags(ActivityFlags.GrantWriteUriPermission);
intent.AddFlags(ActivityFlags.GrantPersistableUriPermission);
intent.SetAction(Intent.ActionView);

intent.SetData(uri);

Context.StartActivity(intent);

问题是,该文件总是只读.当我通过任何文件浏览器(例如 File Manager Pro)打开文档时,它非只读,我可以编辑该文件.

The problem is, that the file is always Read-Only. When I open the document via any file explorer (e.g. File Manager Pro) , it is not Read-Only and I can edit the file.

我是否缺少需要在我的应用或 FileProvider 中设置的任何权限?

Am I missing any permission that i need to set in my app or FileProvider?

  • 我在 Android Word 应用程序中使用我的 Office 帐户登录
  • 使用WPS Office 效果很好,所以一定是 MS-Word 的特殊问题
  • 使用 intent.SetAction(Intent.ActionEdit); 没有区别
  • 使用 intent.SetDataAndType(uri, "application/msword"); 没有任何区别
  • 使用 Google 文档 的类似行为:使用 FileExplorer 我能够打开和编辑文件.如果我通过我的应用程序使用 Google 文档打开文件,我可以编辑该文件,但如果我点击保存,应用程序会要求我将文件更新为新的 DOCX 格式".然后我可以将文件保存到一个新目录.
  • ActionView & 的组合SetDataAndType 因为它在文件资源管理器中使用也不起作用
  • I am logged in with my Office Account in the Android Word App
  • Using WPS Office works just fine, so it has to be a special problem with MS-Word
  • using intent.SetAction(Intent.ActionEdit); does not make a difference
  • using intent.SetDataAndType(uri, "application/msword"); does not make a difference
  • similar behavior using Google Docs: Using a FileExplorer I am able to open and edit the file. If I open the file with Google Docs through my app I can edit the file, but if I click Save, the app asks me to "Update the file to the new DOCX-Format". Then I can save the file to a new directory.
  • The combination of ActionView & SetDataAndType as it is used in the file explorer does not work either

喜欢这个

intent.SetAction(Intent.ActionView);
intent.SetDataAndType(uri, "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

<小时>

意图比较:

我使用了意图拦截应用来比较来自我的应用的意图与来自文件浏览器的意图:

I used an Intent Intercept App to compare the intent from my app with the intent from a file explorer:

我的应用程序(Word 文件是只读的):

File-Explorer(可以编辑 Word 文件):

  • 使用文件浏览器中的 MIME 类型 intent.SetDataAndType(uri, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); 没有区别

推荐答案

如果你使用 ActionEdit 而不是 ActionView 似乎可以工作,而不是

It seems to work if you use ActionEdit instead of ActionView, and NOT

intent.AddFlags(ActivityFlags.GrantPersistableUriPermission);

有了这个,我可以打开一个可编辑的 .doc 文件,但是,我无法将文件保存到原始位置(在我的应用程序的沙箱中).Word 将始终建议保存副本.经过几天的挠头,我怀疑这是微软的设计,我们的代码没有任何问题,尽管我不能确定......

With this, I am able to open a .doc file that is editable, however, I am not able to save the file to the original location (in my app's sandbox). Word will always suggest saving a copy. After scratching my head for days, I suspect this is by design by Microsoft, not anything wrong in our code, though I can't be sure...

这篇关于Word 文档在使用 Intent 打开时始终为只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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