title: Can not read files while reading from local storage
body: <p>I have a method which read files from a particular folder from my phone. I want to share those files via Gmail or other services. It works most of the time but sometime few files are not attached. I have tried so many ways but did not solve this issue yet. I will appreciate if anyone can help me out. Thanks in advance.
  Here is the code sample.</p>
  <pre><code>try {
          File root = Environment.getExternalStorageDirectory();
          File directory = new File(root.getAbsolutePath() + &quot;/logs&quot;);
          File[] files = directory.listFiles();
          attachments.clear();
          if (files != null &amp;&amp; files.length &gt; 0) {
              Log.e(&quot;Report:&quot;, &quot;-------------for loop start--------&quot;);
              for (File value : files) {
                  Log.e(&quot;Report:&quot;, value.getName());
                  Uri uri = FileProvider.getUriForFile(getContext(), &quot;bd.com.cmed.pksf.provider&quot;, value);
                  attachments.add(uri);
              }
              Log.e(&quot;Report:&quot;, &quot;-------------for loop end--------&quot;);
          }
      } catch (Exception e) {
          Log.e(&quot;Report:&quot;, e.getMessage());
      }
  </code></pre>
  <p>Here is the code that I added in AndroidManifest file</p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH_ADMIN&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.BLUETOOTH&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;
  &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot; /&gt;
  
     &lt;provider
          android:name=&quot;androidx.core.content.FileProvider&quot;
          android:authorities=&quot;bd.com.cmed.pksf.provider&quot;
          android:exported=&quot;false&quot;
          android:grantUriPermissions=&quot;true&quot;&gt;
          &lt;meta-data
              android:name=&quot;android.support.FILE_PROVIDER_PATHS&quot;
              android:resource=&quot;@xml/provider_paths&quot; /&gt;
      &lt;/provider&gt;
  </code></pre>
  <p>Path provider file</p>
  <pre><code>    &lt;paths&gt;
       &lt;external-path name=&quot;external_files&quot; path=&quot;.&quot;/&gt;
      &lt;/paths&gt;
  </code></pre>
  <p>Here is the log that I have got.</p>
  <pre><code>    E/Report:: -------------for loop start--------
  E/Report:: member_add.json
  E/Report:: referral_add.json
  E/Report:: -------------for loop end--------
  E/Report:: -------------for loop start--------
  E/Report:: member_add.json
  E/Report:: referral_add.json
  E/Report:: -------------for loop end--------
  E/Report:: -------------for loop start--------
  E/Report:: referral_add.json
  E/Report:: -------------for loop end--------
  E/Report:: -------------for loop start--------
  E/Report:: referral_add.json
  E/Report:: -------------for loop end--------
  E/Report:: -------------for loop start--------
  E/Report:: member_add.json
  E/Report:: referral_add.json
  E/Report:: -------------for loop end--------
  </code></pre>