Image Loader / Explorer Dialog Box (Android 10 update at bottom)

You should just be able to use my updated code, along with your original code. No need for the pimage to bitmap conversion. I have trimmed the permissions code to its bare essentials and it works with your code. Just set it to write_external_storage in caps, and assign the permission fail message you want.

1 Like

Yes, but only if I set my SDK target to 20. I want to be able to use all the other features provided by the newer versions. Your permissions class works OK

I tested the new code using the standard processing ide, sorry forgot to precise this. So no need to downgrade to android 20 apk just build it straight from the PC environment.

That’s odd. I only work with APDE, and it doesn’t except the original + your permissions class without setting to SDK 20.

Ok let me test further, can you check from your machine if it works from your pc (if android mode is installed).

full code

import android.database.Cursor;
import android.content.Intent;
import android.provider.MediaStore;
import android.content.Context;
import android.os.Environment;
import android.Manifest;
import java.awt.FlowLayout;
import java.awt.image.BufferedImage;
private static final int REQUEST_EXTERNAL_STORAGE = 1;
Activity act;
Context mC;
PImage img;
boolean img_loaded;
String s;
Permission eStorage;

void settings() {

void setup() {
  s = Environment.getExternalStorageDirectory().getAbsolutePath();
  eStorage = new Permission(this,"WRITE_EXTERNAL_STORAGE");
  text("Click on screen", width/2, height/3);
  act = this.getActivity();
  mC= act.getApplicationContext();

void draw() {
  if (img_loaded&&img!=null)  image(img, 0, 0);

void mousePressed() {  

public void searchImage() {
  Intent intent = new Intent(Intent.ACTION_PICK, 
  //Activity a = 
  act.startActivityForResult(intent, 1);

  void onActivityResult(int requestCode, int resultCode, Intent data) {

  super.onActivityResult(requestCode, resultCode, data);
  if (requestCode == 1) {
    if (resultCode == Activity.RESULT_OK) {
      if (data != null) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = mC.getContentResolver().query(selectedImage, 
          filePathColumn, null, null, null);
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String imgDecodableString = cursor.getString(columnIndex);
        println( imgDecodableString);
        img = loadImage( imgDecodableString);
        img_loaded = true;
      } else {

public class Permission{
  PApplet parent;
  public boolean requestedPortraitImage = false;

  public Permission(PApplet pParent,String permissionName) {
    parent = pParent;
    parent.requestPermission("android.permission."+permissionName, "onPermissionResult", this);

  public void onPermissionResult(boolean granted) {
    if (!granted) {
      PApplet.println("User did not grant camera permission. Camera is disabled.");


Sorry, I’ve usb connection problems, and never got the virtual device working.

no worries, ive just attempted the code and it also works from apde you just need to set sketch permissions in the properties.

Sure, I know, I always do, but it doesn’t run on my phone.
Did you try my code? Setting to target 29?

Just to confirm are you setting this permission

Gives me the following screen

Of course. I am using APDE for 2,5 years now.

Im. Just super confused…

What version of android are you using, just seeing if we can isolate the problem. I’m on emu 10 for huawei which i think is equivalent to android 10.

Real Android 10 device.
Did you desinstall the previous app, for a clean restart?
Are you using APDE “app mode” not “preview”?

Yeah in app mode not preview

Did you?..

OK, so in preview mode it does not work… Not sure why, in app mode it works even in apk 29. Not sure how to get preview mode working, does app mode also not work for you?


Does it at least run but fails when you load a pic or does it not run at all?

Crashes as soon as I choose picture.

Really sorry no idea why I wrote 29 that was supposed to be on 26, 29 fails on my phone too.

Ps I think I tested with 29 after building once with 26 and that works, but after a clean install 29 fails.