Created
April 25, 2017 09:58
-
-
Save MichaelObi/7209e98fdc881b41d3479434d303629c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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