简体   繁体   中英

Issue Writing to external storage

I'm working from this tutorial of how to add camera functionality in my app and save the photos taken.

https://developer.android.com/training/camera/photobasics.html

With this version I can not find the photo's after when saving using

getExternalFilesDir(Environment.DIRECTORY_PICTURES);

The camera works but the pictures are nowhere to be found after.

I have tried to use

getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)

However with this the camera does not even load.

Any advice on why this may be happening would be much appreciated.

You and Camera both can not use the Environment.DIRECTORY_DCIM at the same time. So when you are trying to access the same and then try to use camera as well, then at that time Camera also tries to access Environment.DIRECTORY_DCIM which is already acquired by you. Hence Camera does not work for that time.

To implement the Camera in your app:

Intent e = new Intent("android.media.action.IMAGE_CAPTURE");
String state = Environment.getExternalStorageState();
Uri mImageCaptureUri = your required file path's URI;
e.putExtra("output", mImageCaptureUri);
e.putExtra("return-data", true);
startActivityForResult(e, 1);

Now use onActivityResult method to access the captured image.

You can use the below direction to save your files in the internal storage

 String PicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();

then you will find your save files in the below path /storage/emulated/0/Android/data/ your package name /files/Pictures/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM