Porting sketch to Android Studio - Problem with request permission

I am porting a sketch to Android Studio. The problem is: In setup() i have

requestPermissons(…)

In Android studio this doesn’t work, my app quits. So i tried to change to

ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 11);

But this doesn’t work since my class is extending PApplet not Main Activity.
callind that from Main Activity doesn’t help either, because my Class seems not to be at Main Activity. I just used export sketch as Android Studio Project.

What else could I try so my sketch gets read/write access to Externaö Storage when run from Android Studio?

@sensn===

you can ask for permissions in setup() creating 2 (or three) methods:

Activity act;
act this.getActivity();////you are in a fragment (or PFragment which extends Fragment)
----------

//first method::
 private void demandePermissionParticuliere(){
act.requestPermissions(new[]{Manifest.permission.YOURPERMISSION, 101);/ /adding some value for request code: 101; could be another int!
};
//second method:::
public void onRequestPermissionsResult(int requestCode,String[] permissions, int[] grantResults){
switch (requestCode){
case 101:
if (grantResults[0] PackageManager.PERMISSION_GRANTED){
println("permissions accordées");
else{
println("permissions not granted");
}
break;
default:
act.onRequestPermissionsResult(requestCode, permissions,grantResults);
}
}

----call the first one in setup()

–the third method could be to verify that the permissions were already granted

–fourth one could be to change according the os phone (pre-lollipop)

This looks good, but i get syntax error in Android studio. Tried to add a curly bracket on various places, but it also says identifier expected on new

Could you help me…

@sensn===

of course! i have written too fast! -: new does not mean nothing! it’ s new String[]{…

OK,

act.requestPermissions( new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 10);

works as far as it is now asking for permission. still no file written by Table class.

Hm, maybe i got another mistake in my code. testing…

thanks a lot

act = this.getActivity(); I missed that one.

Can it be that Tableclass needs some adjustment too? it doesn’t write any file when used with Android Studio.

Same code runs fine with processing.

EDIT: Path issue. Solved