In my app project, I want to take picture from second-front camera and it is saved in StringFormat like "yyyy-mm-dd hh:mm". I use this code,but it TOASt me:"Can't Saved."(try-catch part). would you please help me, why my photo doesn't save?
public onPictureTaken(byte[] data, Camera camera) {
File pictureFileDir = new File(Environment.getExternalStorageDirectory(), "Dahesh");
pictureFileDir.mkdir();
if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
Log.d(DEBUG_TAG, "Can't create directory to save image");
Toast.makeText(this, "Can't make path to save pic.",
Toast.LENGTH_LONG).show();
return;
}
Calendar calender =Calendar.getInstance();
SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-mm-dd hh:mm:ss a");
//String fileName = simpleDateFormat.format(calender.getTime());
String fileName =pictureFileDir.getPath() + File.separator + simpleDateFormat.format(calender.getTime());
fileName=fileName.replace(":","_");
fileName=fileName.replace("","_");
File pictureFile =new File(fileName);
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
Toast.makeText(this, "Image saved as latest_mug.jpg",
Toast.LENGTH_LONG).show();
} catch (Exception error) {
Log.d(DEBUG_TAG, "File not saved: " + error.getMessage());
Toast.makeText(this, "Can't save image.", Toast.LENGTH_LONG).show();
}
}
Did you even write that code? Anyway, it's probably due to the mounted filesystem not allowing characters like ':' try to change your formatting so it doesn't have any special characters.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다