Android Cannot get access to data folder

@PhoenixStormJr
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.beginDraw();
  img.fill(0, 0, 150);
  img.rect(0, 0, 200, 200);
  img.textSize(30);
  img.textAlign(CENTER,CENTER);
  img.fill(255);
  img.text("My Image",img.width/2, img.height/2);
  img.endDraw();
  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/");
  img.save(directory_path + "myImageName.png");
}
1 Like