title: Android 11 sharing file between apps
body: <p>Android 11 had enforce some rules for storage, link refer : <a href="https://developer.android.com/about/versions/11/privacy/storage" rel="noreferrer">Storage updates in Android 11</a></p>
  <p>Use Case :
  I have 2 applications, application A will write file <strong>(.txt)</strong> into external storage, application B will read the file from external storage <strong>without user interaction</strong>. But exception was thrown when read / write on Android 11, stated that permission was denied.</p>
  <p>So I did some research and found that only <em>MediaStore API</em> and <em>Storage Access Framework</em> allow access files that created by other application, link refer : <a href="https://developer.android.com/training/data-storage" rel="noreferrer">Data and file storage overview</a></p>
  <p>But both methods are not suitable for my use case:</p>
  <ul>
  <li><em>MediaStore API</em> can only access Media files(images, audio files, videos)</li>
  <li><em>Storage Access Framework</em> need user interaction</li>
  </ul>
  <p>So is there any other way that I can access non-media files on external storage that created by different apps on Android 11?</p>
  <p>Despite all my researches, I didn't find a solution to my problem.</p>
  <p>Thank you for your help.</p>
  <p><strong>Updates</strong></p>
  <p>I tried <a href="https://developer.android.com/reference/androidx/core/content/FileProvider" rel="noreferrer">FileProvider</a> but when I tried start activity, it always show error</p>
  <blockquote>
  <p>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.testapp, PID: 20141
  android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.app2.action.RECEIVE dat=content://com.example.testapp.fileprovider/myfiles/default_user.txt flg=0x1 }
  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2067)
  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
  at android.app.Activity.startActivityForResult(Activity.java:5320)</p>
  </blockquote>
  <p>This is how I start App 2 activity from App 1</p>
  <pre><code>File filePath = new File(getFilesDir(), &quot;files&quot;);
  File newFile = new File(filePath, &quot;default_user.txt&quot;);
  Intent intent = new Intent();
  intent.setAction(&quot;com.example.app2.action.RECEIVE&quot;);
  intent.setData(FileProvider.getUriForFile(this, &quot;com.example.testapp.fileprovider&quot;, newFile));
  intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  startActivity(intent);
  </code></pre>
  <p>App 1 Manifest</p>
  <p></p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.FOREGROUND_SERVICE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
  
  &lt;application
      android:allowBackup=&quot;true&quot;
      android:requestLegacyExternalStorage=&quot;true&quot;
      android:icon=&quot;@mipmap/ic_launcher&quot;
      android:label=&quot;@string/app_name&quot;
      android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
      android:supportsRtl=&quot;true&quot;
      android:theme=&quot;@style/Theme.TestApp&quot;&gt;
      &lt;activity android:name=&quot;.StorageActivity&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
              &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name=&quot;.MainActivity&quot;&gt;
      &lt;/activity&gt;
  
      &lt;service
          android:name=&quot;.service.TestService&quot;
          android:enabled=&quot;true&quot;
          android:exported=&quot;true&quot; /&gt;
  
      &lt;provider
          android:name=&quot;androidx.core.content.FileProvider&quot;
          android:authorities=&quot;com.example.testapp.fileprovider&quot;
          android:grantUriPermissions=&quot;true&quot;
          android:exported=&quot;false&quot;&gt;
          &lt;meta-data
              android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;
              android:resource=&quot;@xml/filepaths&quot; /&gt;
      &lt;/provider&gt;
      
  &lt;/application&gt;
  </code></pre>
  
  <p>App 2 Manifest</p>
  <p></p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
  
  &lt;application
      android:allowBackup=&quot;true&quot;
      android:icon=&quot;@mipmap/ic_launcher&quot;
      android:label=&quot;@string/app_name&quot;
      android:requestLegacyExternalStorage=&quot;true&quot;
      android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
      android:supportsRtl=&quot;true&quot;
      android:theme=&quot;@style/Theme.TestApp&quot;&gt;
      &lt;activity android:name=&quot;.ReceiverActivity&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;com.example.app2.action.RECEIVE&quot;/&gt;
  
              &lt;category android:name=&quot;android.intent.category.DEFAULT&quot;/&gt;
              &lt;data android:scheme=&quot;content&quot;
                  android:host=&quot;com.example.testapp&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name=&quot;.MainActivity&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
              &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>