I'm working with camera in android and I'm new to android camera. I've followed the tutorial from here
Whenever I'll add External storage permission in android manifest, camera saves it in default directory without asking me and I want to save it in my own folder created in sd card. I'd searched a lot but couldn't find any useful link. Please help, any help will be much appreciated. Thank you :)
You can add this code in onActivityResult. This will store your image in a folder named "YourFolderName"
String extr = Environment.getExternalStorageDirectory().toString()
+ File.separator + "YourFolderName";
File myPath = new File(extr, fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
bitMap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(context.getContentResolver(),
bitMap, myPath.getPath(), fileName);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
also need to set permission on Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
camera saves it in default directory without asking me and I want to save it in my own folder created in sd card
You can tell the camera where you would like the photo to be stored via EXTRA_OUTPUT
, as is shown in the documentation's training module on ACTION_IMAGE_CAPTURE
.
There is no requirement for all cameras to store images where you ask it to, though. If the file that you ask for does not exist after the image is taken, you will need to fall back to your existing application logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With