Save captured image in a specific folder on the SD card

I am working with a camera on an android, and I am new to an android camera. I followed the tutorial from here

Whenever I add permission to external storage in the Android manifest, the camera saves it in the default directory without asking me, and I want to save it in my own folder created on the SD card. I searched a lot, but did not find any useful link. Please help, any help would be greatly appreciated. Thanks:)

+6
source share
3 answers

You can add this code to onActivityResult. This will save 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(); } 

manifest permission must also be set

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
+4
source
Camera

saves it in the default directory without asking me, and I want to save it in my own folder created on the SD card.

You can tell the camera where you want to save the photo via EXTRA_OUTPUT , as shown in the documentation training module at ACTION_IMAGE_CAPTURE .

However, all cameras do not need to store images where you ask for it. If the file you are requesting does not exist after the image is captured, you will need to revert to the existing application logic.

+1
source

You can assign a path to write image data to a specific location, for example:

 String fileName = "/mnt/sdcard/foldername"; FileOutputStream fos = new FileOutputStream(fileName); fos.write(data); 
0
source

Source: https://habr.com/ru/post/973649/


All Articles