I am trying to get Android’s MediaStore to write an image to the SD card with a specific file name. It does write the file, but does not use the title parameter passed with
MediaStore.Images.Media.insertImage(cr, source, title, description)
Here is my relevant code:
PictureCallback myPictureCallback_JPG = new PictureCallback(){
public void onPictureTaken(byte[] arg0, Camera arg1) {
Bitmap bitmapPicture = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
int year = Calendar.getInstance().getTime().getYear();
int month = Calendar.getInstance().getTime().getMonth();
int day = Calendar.getInstance().getTime().getDay();
int hour = Calendar.getInstance().getTime().getHours();
int minute = Calendar.getInstance().getTime().getMinutes();
int seconds = Calendar.getInstance().getTime().getSeconds();
String imgName = "IMG_" + Integer.toString(year) + Integer.toString(month) +Integer.toString(day) + "_" + Integer.toString(hour) + Integer.toString(minute)
+ Integer.toString(seconds) + ".jpg";
MediaStore.Images.Media.insertImage(getContentResolver(), bitmapPicture, imgName, imgName);
camera.startPreview();
inPreview=true;
}};
It successfully stores the picture, but the file name appears to be time since the Unix epoch (i.e. 13168297…16.jpg)
I didn’t get MediaStore to work, but I did use the File class and FileOutputStream to get the job done: