Word document is always Read-Only when opened with Intent

浪子不回头ぞ 提交于 2019-11-30 03:20:26

问题


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

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.

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

EDIT:

  • 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

like this

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

Intent Comparision:

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


My App (Word file is Read-Only):


File-Explorer (Word file can be edited):

  • using MIME-type from the file explorer intent.SetDataAndType(uri, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); does not make a difference

来源:https://stackoverflow.com/questions/56287019/word-document-is-always-read-only-when-opened-with-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!