Android Cannot get access to data folder

I have all permissions enabled. I also do not see the </> button.

Is the button <> because I do not see </>?

Why all permissions? I’ve never tried that. Just choose WRITE_EXTERNAL_STORAGE
I’ll try on an unrooted phone.
See below the buttons how they show up on my device.

Just tested it on a not rooted phone Lollipop.
Works perfectly when enabled the write permission. Without this permission it gives exactly the error you posted. Are you using APDE just using this single permission?
Edit: I just realized that you misunderstood when I said “You can edit your code”. I meant the code of your post, not the IDE, because it is somewhat annoying having to scroll so much. The preview mode really has the <> button.:blush:


I tried that one permission… guess its just my phone sucks. Thank you for trying and i see the </> button.

good, can you PLEASE use it to repair all your above posts? about CODE or ERROR

and i check older posts like
Multiple Sine Waves - #2 by PhoenixStormJr ,
and WOW good formatting,

but then i see moderator @jeremydouglass did it for you!
and you not learned anything!

1 Like

I do clean up old posts regularly – but sometimes this may mean I confuse new forum users into thinking that forum formatting happens automatically. :shrug: not anyone’s fault, but it is good to politely remind everyone to format their code; thanks for doing that.

1 Like

@PhoenixStormJr Try reinstalling APDE or Android mode on PC.

1 Like

I think I know where things went wrong. I’ll try to make it as simple as possible.
In the code below I will only use two lines of code to save the image. The first line uses an android function to get the absolute path. When you open the Android File Explorer you will see folders above the absolute path, like DCMI or Sketchbook. But there are underlying folders, and that is why you need to call the absolute folder path. Then you add the resting folders above that level. That is what the first line does. Note that the folders are between backslashes.
You have to verify that the folders really exist, otherwise you have to create them first. Just change the folder name of your sketch and the image.
You can save the file as PImage or PGraphics. The first I only used to show the image as soon as created.
Now I think, things are good to go.
You can download the code here


import android.os.Environment;

PImage myImage;
PGraphics img;

void setup() {
  size(200, 200);
  img = createGraphics(200, 200);
  img.fill(0, 0, 150);
  img.rect(0, 0, 200, 200);
  img.text("My Image",img.width/2, img.height/2);
  image(img, 0, 0);
  myImage = get(0, 0, 200, 200);
  image(myImage, 0, 0);
  String directory_path = new String(Environment.getExternalStorageDirectory().getAbsolutePath() + "/sketchBook/mySketchFolder/data/"); + "myImageName.png");
1 Like

I reinstalled processing and used your code but i am still getting errors. I also reapplied my permissions. It doesn’t seem like I’m getting anywhere and I’m beggining to think it’s impossible for Samsung galaxy phones especially since I dont even have access to the processing folder for stupid non root.

Unrelated: (And for the </> button when I copy code it copies in a straight line and i have to press enter 100 times to get any of it to work so sorry if i made anyone angry)

I am also on android so when I tried to download it I got “error no app capable of opening file…” or something.

My devices are Samsung also. Phone S4, and Tablet E 9.6
But both have normal access to the sketch folder. There must be something wrong with your phone. Can’t you try it on another phone?

1 Like

After you get storage permission, you can use following method to get root path.

    public static String getRootFilesDirPath() {
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
            File[] files = ContextCompat.getExternalFilesDirs(getContext().getApplicationContext(),null);
            return files[0].getAbsolutePath();
        } else {
            return getContext().getFilesDir().getAbsolutePath();
Initializing build sequence…
Deleted old build folder
Injected log broadcaster
Detected architecture armeabi-v7a

Packaging resources with AAPT…
Compiling with ECJ…
1. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/save_picture/ (at line 25)
	File[] files = ContextCompat.getExternalFilesDirs(getContext().getApplicationContext(),null); 
ContextCompat cannot be resolved
2. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/save_picture/ (at line 25)
	File[] files = ContextCompat.getExternalFilesDirs(getContext().getApplicationContext(),null); 
Cannot make a static reference to the non-static method getContext() from the type PApplet
3. ERROR in /data/user/0/com.calsignlabs.apde/app_build/src/processing/test/save_picture/ (at line 29)
	return getContext().getFilesDir().getAbsolutePath(); 
Cannot make a static reference to the non-static method getContext() from the type PApplet
3 problems (3 errors)
Compiling with ECJ failed

Well it works on bluestacks but i need my computer for that. Also i dont have another phone. Well now i know my phone sucks. Atleast its not me. Thank you for all your work i really appreciate it now i just gotta fix this thing… somehow

@PhoenixStormJr , @noel ===
the code given by @noel must run on your phone and the error you can get with it is only if you dont get the WRITE_EXTERNAL_STORAGE permission; as it seems to me that @noel is using lollipop he does not ask for permissions on runtime but if your phone is using more than lollipop YOU HAVE TO ASK for this permission on runtime & by code, asking only with the Manifest will not work…

1 Like

@akenaton Lollipop also requires this permission. The app APDE, (entirely based on Processing for Android) has an extra feature. It can run in a “preview” mode. Preview mode skips several steps of the build process: DX-Merge , APKBuilder, ZipSigner, and installation. The only significant remaining steps are AAPT, ECJ , and DX-Dex, so the build process is much more streamlined. The preview mode also gives automatic permissions. But when you want to export, using the “app” mode, permissions are required. On a Galaxy S9+, the entire process to run code, takes less than two seconds. Codeanticode was talking about implementing it in PC android as well. APDE is a free open source project from calsign and I really would ike to see them together on one Github. I was never able to run Processing for Android in emulator mode. And running on device directly with a usb cable, takes minutes every time. You could give it a try☺.

@noel ====

Lollipop also requires this permission

yes but NOT in runtime && by code…

Isn’t ContextCompat a part of support library v4? How did you add support library 4 into your processing project?

1 Like

We don’t give up easily. Let’s do a test the other way around. With the link below you can download a small app that saves and loads images into a folder on your phone (with the same code). It is a zoomable Mandelbrot image generator. If it doesn’t run you maybe have to reset your phone.
This way you’ll also help me to verify if my methods for text and other views, automatic resizing on different screen resolutions, work properly. I would also appreciate testing by others.
The link for the apk pure here and zipped here.

The app looks this way on my phone.