-1

I have my app so I have the ability to open the camera and take a picture, the app then shows me a preview of the photo just taken, and when I press 'OK', it is gone. I want to be able to save the image I have taken to my internal storage on my phone, (and possibly have a function so I can access my gallery and preview it later on). I have searched everywhere but all the help I am getting is to store it on an SD card, whereas I want to use my phones built in storage. Thank you

My code so far:

Button butCamera;
ImageView imageView;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_camera);

    butCamera = (Button) findViewById(R.id.butCamera);
    imageView = (ImageView) findViewById(R.id.imageView);



    butCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, 0);
        }

});
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    Bitmap bitmap = (Bitmap)data.getExtras().get("data");
    imageView.setImageBitmap(bitmap);

}
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
Boi
  • 23
  • 7
  • 2
    Internal storage means app-private storage in android dev. Shared storage is external storage, and can be the SD card. But not necessarily – Zoe Dec 18 '17 at 18:48
  • "android save picture to internal storage" would make a really good web search. It sure would. –  Dec 18 '17 at 18:55
  • what is your butCamera button for? is it the button for saving the image? – Kennedy Dec 18 '17 at 19:15
  • Take a look at this post, it should have what you need https://stackoverflow.com/questions/8560501/android-save-image-into-gallery – Kennedy Dec 18 '17 at 19:43

2 Answers2

0

What you are trying to achieve is quite complex, an i'm not sure you could use this common storage method to achieve it

File root = Environment.getExternalStorageDirectory();

But have a loot at this post, it should have what you require

android - save image into gallery

Kennedy
  • 547
  • 4
  • 23
-1

To store the Image to Internal storage of the device, you will have to do something like this.

File file = new File(Environment.getExternalStorageDirectory(), "MyFile.jpg");
Uri uri = Uri.fromFile(file);

intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

startActivityForResult(intent, CAMERA_REQUEST);
Saran Sankaran
  • 2,335
  • 2
  • 19
  • 34