title: Xamarin.Forms Android FileProvider: GrantWriteUriPermission not always working
body: <p>I want to <strong>edit</strong> files from the internal storage of my Xamarin.Forms Android app in third party apps, for example fill out form elements in a PDF file or edit a .docx file.</p>
  
  <p>With my implementation the file gets correctly opened in the external app, but in certain apps it is opened <strong>read-only</strong>. 
  Adobe Acrobat and Microsoft Word open the files read-only, while other apps like Google Docs are able to write back into the file.
  (I am using Microsoft Word with a valid Office365 subscription).</p>
  
  <p>My FileProvider in the AndroidManifest.xml:</p>
  
  <pre><code>&lt;provider android:name="android.support.v4.content.FileProvider" 
            android:authorities="xamarintestapp.xamarintestapp.fileprovider" 
            android:grantUriPermissions="true" 
            android:exported="false"&gt;
      &lt;meta-data android:name="android.support.FILE_PROVIDER_PATHS"     
                 android:resource="@xml/filepaths" /&gt;
  &lt;/provider&gt;
  </code></pre>
  
  <p>filepaths.xml:</p>
  
  <pre><code>&lt;paths&gt;
          &lt;files-path name="files" path="."/&gt;
  &lt;/paths&gt;
  </code></pre>
  
  <p>Via the Xamarin.Forms DependencyService I am starting a Activity and pass the content uri to launch the external app:</p>
  
  <pre><code>public void OpenFile(string fileName)
  {
      string auth = "xamarintestapp.xamarintestapp.fileprovider";
      string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(fileName.ToLower()));
      if (mimeType == null)
          mimeType = "*/*";
  
      var file = new Java.IO.File(Path.Combine(Forms.Context.FilesDir.Path, fileName));
      Android.Net.Uri uri = FileProvider.GetUriForFile(Forms.Context, auth, file);
  
      Intent intent = new Intent(Intent.ActionView);
      intent.SetDataAndType(uri, mimeType);
      intent.AddFlags(ActivityFlags.GrantReadUriPermission | ActivityFlags.GrantWriteUriPermission);
      intent.AddFlags(ActivityFlags.NewTask | ActivityFlags.NoHistory);
  
      // Trying to allow writing to the external app ...
      var resInfoList = Forms.Context.PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
      foreach (var resolveInfo in resInfoList)
      {
          var packageName = resolveInfo.ActivityInfo.PackageName;
          Forms.Context.GrantUriPermission(packageName, uri, ActivityFlags.GrantWriteUriPermission | ActivityFlags.GrantPrefixUriPermission | ActivityFlags.GrantReadUriPermission);
      }
  
      Forms.Context.StartActivity(intent);
  }
  </code></pre>
  
  <p>Am I doing something wrong or is this simply not possible?</p>