title: I tried to view an image from /storage/emulated/0/Pictures using BitmapFactory - but see error permision denied
body: <p>I started a new project in Android Studio with: empty activity, Java, API 29, Android 10.0 (Q)</p>
  <p><strong>I added permissions to AndroidManifest.xml</strong></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;
  </code></pre>
  <p><strong>I added ImageView and a Button to activity_main.xml</strong></p>
  <pre><code>    &lt;Button
          android:id=&quot;@+id/button&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginTop=&quot;80dp&quot;
          android:text=&quot;button&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
      &lt;ImageView
          android:id=&quot;@+id/my_image&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/button&quot;
          /&gt;
  </code></pre>
  <p><strong>I loaded an image in MainActivity.java</strong> - Permissions are checked at run time, after a button click. Then after another button click the image should be viewed. The code also contains a few checks for correct activity.</p>
  <pre><code>package mrppanther.com.example.read_image;
  
  import android.Manifest;
  import android.content.pm.PackageManager;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.Toast;
  import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.core.app.ActivityCompat;
  import java.io.File;
  
  public class MainActivity extends AppCompatActivity {
      private int STORAGE_PERMISSION_CODE = 1;
      private int new_state = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          // NOTE: use a button to request activity
          Button buttonRequest = findViewById(R.id.button);
          buttonRequest.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  // NOTE: declare &quot;myfile&quot;, this is want I want to view
                  File myfile = new File(&quot;/storage/emulated/0/Pictures/henry1.jpg&quot;);
  
                  // NOTE: on the 1st click, check permissions
                  if (new_state == 1) {
                      requestStoragePermission();
                      new_state = 2; // NOTE: move to the next state, on the next click
  
                  // NOTE: on the 2nd click, view image
                  } else {
  
                      // NOTE: check that the &quot;myfile&quot;&quot; exists
                      if (myfile.exists()) {
                          Log.i(&quot;myfile&quot;, &quot;FILE EXISTS PASS! &quot; + myfile);
                      } else {
                          Log.i(&quot;myfile&quot;, &quot;FILE ABSENT FAIL! &quot; + myfile);
                      }
  
                      // NOTE: declare &quot;myimage&quot;
                      ImageView myimage = (ImageView) findViewById(R.id.my_image);
  
                      // NOTE: experimenting with options did not help
                      BitmapFactory.Options options=new BitmapFactory.Options();
                      //options.inJustDecodeBounds=true;
                      options.inSampleSize=1;
  
                      // ERROR: E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException:
                      // ERROR: /storage/emulated/0/Pictures/henry1.jpg: open failed: EACCES (Permission denied)
                      Bitmap bitmap = BitmapFactory.decodeFile(String.valueOf(myfile), options);
  
                      myimage.setImageBitmap(bitmap);
  
                      // NOTE: here is a test to check &quot;myimage&quot; is correct
                      // NOTE: this works OK, and image from drawable resource is displayed
                      // myimage.setImageResource(R.drawable.henry1);
  
                      new_state = 1; // NOTE: go back to the 1st state, on the next click
                  }
              }
          }); // NOTE: this is the end of button activity
      }
  
      // NOTE: request permission to read storage, at run time
      private void requestStoragePermission() {
          ActivityCompat.requestPermissions(this,
                  new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);
          // NOTE: here is a test which sets the wrong permission
          // new String[]{Manifest.permission.READ_PHONE_NUMBERS,Manifest.permission.READ_PHONE_STATE}, STORAGE_PERMISSION_CODE);
      }
  
      // NOTE: check read permission is granted, at run time
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          if (requestCode == STORAGE_PERMISSION_CODE) {
              if (grantResults.length &gt; 0 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  Toast.makeText(this, &quot;Permission GRANTED&quot;, Toast.LENGTH_SHORT).show();
              } else {
                  Toast.makeText(this, &quot;Permission DENIED&quot;, Toast.LENGTH_SHORT).show();
              }
          }
      }
  }
  </code></pre>
  <p><strong>Results:</strong> I saw the error message below, and the image was not displayed.
  However, the run time permission check indicated &quot;Permission GRANTED&quot;. Finally I rebooted my Tablet. I checked the app is allowed access to storage (in settings, app, storage permission). I reran the app with USB disconnected, but the image was not displayed.</p>
  <pre><code>I/myfile: FILE EXISTS PASS! /storage/emulated/0/Pictures/henry1.jpg
  E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/Pictures/henry1.jpg: open failed: EACCES (Permission denied)
  </code></pre>