title: Open files in external apps with android (API 30) file provider with write access
body: <p>I want to open files from my Android app (Cordova) in external apps with write access, so they can make changes. (Example: sign a PDF).</p>
  <p>The files to open are under external-files-path and can be opened. Unfortunately, the changes are not saved.</p>
  <p>Since Android 11 (API Level 30) the file:// calls don't work anymore (with disableDeathOnFileUriExposure hack). With the content:// call I get no write access passed to the app.</p>
  <p>I use the following logic to open the file (the coding is from <a href="https://github.com/pwlin/cordova-plugin-file-opener2" rel="nofollow noreferrer">https://github.com/pwlin/cordova-plugin-file-opener2</a>):</p>
  <pre><code>File file = new File(fileName);
  Intent intent = new Intent(Intent.ACTION_VIEW);
  Context context = cordova.getActivity().getApplicationContext();
  Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + &quot;.fileOpener2.provider&quot;, file);
  intent.setDataAndType(path, contentType);
  intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
  if (openWithDefault) {
      cordova.getActivity().startActivity(intent);
  } else {
      cordova.getActivity().startActivity(Intent.createChooser(intent, &quot;Open File in...&quot;));
  }
  </code></pre>
  <p>AndroidManifest.json</p>
  <pre><code>&lt;provider android:authorities=&quot;${applicationId}.fileOpener2.provider&quot; android:exported=&quot;false&quot; android:grantUriPermissions=&quot;true&quot; android:name=&quot;io.github.pwlin.cordova.plugins.fileopener2.FileProvider&quot;&gt;
      &lt;meta-data android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot; android:resource=&quot;@xml/opener_paths&quot; /&gt;
  &lt;/provider&gt;
  </code></pre>
  <p>opener_paths.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;paths xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
      &lt;files-path name=&quot;files&quot; path=&quot;.&quot; /&gt;
      &lt;cache-path name=&quot;cache&quot; path=&quot;.&quot; /&gt;
      &lt;external-files-path name=&quot;external-files&quot; path=&quot;.&quot; /&gt;
      &lt;external-cache-path name=&quot;external-cache&quot; path=&quot;.&quot; /&gt;
      &lt;external-path name=&quot;external&quot; path=&quot;.&quot; /&gt;
  &lt;/paths&gt;
  </code></pre>