# Android camera .. save image

**URL:** <https://discourse.processing.org/t/android-camera-save-image/731>\
**Category:** Processing for Android\
**Created:** [June 5, 2018, 4:41pm UTC](https://discourse.processing.org/t/android-camera-save-image/731 "2018-06-05T16:41:35Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [May 23, 2020, 1:38pm UTC](https://discourse.processing.org/t/android-camera-save-image/731/7 "2020-05-23T13:38:27Z")

</div>

@adaptinnovative ===  
I have written the code initially put; i have tested it again (OS6 MM), with some little modifs and it works: i can see the folder “camerademo” inside PICTURES and i can see the photo inside it. It is possible that URIfromFile does not work for OS\>6 MM, yet you can try and it s esay to change this part of the code. Dont forget to ask permissions on rutime if you using a phone more than lollypop.

```auto
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
 import android.os.Environment;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
int MyVersion = Build.VERSION.SDK_INT;
Intent intent; 
Uri file; 

public static final int CAMERA_REQUEST = 1;

Activity act;
boolean accordees = false;
 
public void setup(){
  orientation(LANDSCAPE);
  size(displayWidth, displayHeight);
  act = this.getActivity();
 ///here ask for permissions: CAMERA, WRITE_EXTERNALSTORAGE on rutime, not only through the Manifest
  Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                    
  Uri file = Uri.fromFile(getOutputMediaFile());
  println(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, file);
  act.startActivityForResult(intent,CAMERA_REQUEST );

};
  
  
public void onActivityResult(int requestCode, int resultCode, Intent data)
   {
      super.onActivityResult( requestCode, resultCode, data);
        
      if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK){
      println("camera ok); 
        
    }
      
  };
 
 
public void draw(){
 
}

private static File getOutputMediaFile(){
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES), "CameraDemo");
 
    if (!mediaStorageDir.exists()){
        if (!mediaStorageDir.mkdirs()){
            return null;
        }
    }
 
   
    return new File(mediaStorageDir.getPath() + File.separator +
                "IMG_"+ System.currentTimeMillis() + ".jpg");
};

```

---

_[View the full topic](https://discourse.processing.org/t/android-camera-save-image/731)._
