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?
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)