Skip to content

Instantly share code, notes, and snippets.

@MichaelObi
Created April 25, 2017 09:58
Show Gist options
  • Save MichaelObi/7209e98fdc881b41d3479434d303629c to your computer and use it in GitHub Desktop.
Save MichaelObi/7209e98fdc881b41d3479434d303629c to your computer and use it in GitHub Desktop.
mCameraSource.takePicture(null, new CameraSource.PictureCallback() {
@Override
public void onPictureTaken(byte[] bytes) {
try {
File basePath = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
if (!basePath.exists()) {
Log.d("CAPTURE_BASE_PATH", basePath.mkdirs() ? "Success" : "Failed");
}
File captureFile = new File(basePath + File.separator + "vstyle_photo_" + (new Date().getTime()) + ".jpg");
if (!captureFile.exists())
Log.d("CAPTURE_FILE_PATH", captureFile.createNewFile() ? "Success" : "Failed");
FileOutputStream stream = new FileOutputStream(captureFile);
stream.write(bytes);
stream.flush();
stream.close();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(captureFile)));
} catch (IOException e) {
e.printStackTrace();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment