1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
try{
SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss");
final String fileName = "photo_" + timeStampFormat.format(new Date()) + ".jpg";
ContentValues values = new ContentValues();
values.put(Media.TITLE, fileName);
values.put(Media.DISPLAY_NAME, fileName);
values.put(Media.DESCRIPTION,"dev");
values.put(Media.DATE_TAKEN, new Date().getTime());
values.put(Media.MIME_TYPE, "image/jpeg");
final Uri taken = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
final FileOutputStream stream = (FileOutputStream) getContentResolver().openOutputStream(taken);
Camera.PictureCallback pictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
if (data != null)
{
try {
if (stream != null) {
stream.write(data);
stream.flush();
stream.close();
}
}
catch (Exception e)
{
//check error
} |
Partager