# Permission issue in reading file from external storage

**URL:** <https://discourse.processing.org/t/permission-issue-in-reading-file-from-external-storage/34184>\
**Category:** Processing for Android\
**Created:** [December 18, 2021, 1:13pm UTC](https://discourse.processing.org/t/permission-issue-in-reading-file-from-external-storage/34184 "2021-12-18T13:13:46Z")\
**Posts on this page:** 1\
**Showing post:** 44

<div class="post-metadata">

**Author:** ![bigboss97](https://avatars.discourse-cdn.com/v4/letter/b/47e85d/32.png) [@bigboss97](https://discourse.processing.org/u/bigboss97)\
**Post date:** [January 2, 2022, 3:52am UTC](https://discourse.processing.org/t/permission-issue-in-reading-file-from-external-storage/34184/44 "2022-01-02T03:52:39Z")

</div>

OK, I got it working on Android 11. But first of all a huge THANK to @jafal with all the sample codes.  
I modified the loadImage() routine for my purpose:

```auto
import android.os.Environment;
import java.io.FileInputStream;
import android.Manifest; 
import android.content.pm.PackageManager;
import android.app.Activity; 
import android.os.Build; 
import android.os.Build.VERSION_CODES; 

Activity activity; 
JSONObject json;

private static String[] PERMISSIONS_STORAGE = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE }; 
private void requestParticularPermission() { 
  activity.requestPermissions(PERMISSIONS_STORAGE, 2020);
}
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 
  switch (requestCode) { 
  case 2020: 
    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
      println("permissions granted");
    } else { 
      println("permissions not granted");
    } 
    break; 
  default: 
    activity.onRequestPermissionsResult(requestCode, permissions, grantResults);
  }
}

void setup() {
  activity = this.getActivity();
  if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1)
    requestParticularPermission();
}

void draw() {
}

void mousePressed() {
  String dir= new String(Environment.getExternalStorageDirectory().getAbsolutePath());
  try {
    json = loadJSONObject( dir+"/twinkBOSS/env.txt");
    println( json.getString("ip"));
  }
  catch ( Exception e) {
    println(e);
  }
}

```

When the above code is run there will be a popup asking for permission, but photos and media only. That’s the reason that loading image wasn’t an issue.

 ![Screenshot_20220102-143530_Permission controller](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2e39fb31466ad65aeb75f882e835ee4f3add1669.png)

When I checked the app on the phone I saw the issue:

 ![Screenshot_20220102-143818_Permission controller](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a58ad125f8bf0efc00baaf4a5d28c24755b7b42a.png)  
I had to allow all files. Then all work 😄

Again, thank you for your time, @jafal 👍

---

_[View the full topic](https://discourse.processing.org/t/permission-issue-in-reading-file-from-external-storage/34184)._
