Answer the question
In order to leave comments, you need to log in
Android 10(SDK 29). How to create a directory in DCIM?
Good day. I must say right away that I am not an android developer. Essence. Two years ago, my wife moved to a new job. There it was necessary to photograph various objects, name files with pictures in a special way and further process them. She took the photo with her phone. Renaming took a lot of time and was a chore. I bungled a simple application by touch - it asked for a file number (with a prefix prefixed), opened the camera, took a picture and saved with a specific name (prefix + numbers entered by the user). All this economy worked fine on Android 7.0. But then an opportunity happened - the device was changed to Android 10 and the program stopped working. Through witchcraft, sacrifices and fiddling with the debugger, it turned out that the problem is in this piece
private File getOutputMediaFile(String filename)
{
File mediaStorageDir = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)+File.separator+"Camera"+File.separator+filename+File.separator);
if (!mediaStorageDir.exists()){
if (!mediaStorageDir.mkdirs()){
Log.d("AutoCAMERA", "failed to create directory");
return null;
}
}
return new File(mediaStorageDir.getPath()+File.separator+filename+".jpg");
}
android:requestLegacyExternalStorage="true"
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question