I know there are lots of examples of this, but I haven't found a solid example that works with 7.0+. I know that I am setting the thumbnail of the image rather than the original, but I am not sure how to get it.
Here is my code:
if( ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.CAMERA},
CAMERA_REQUEST_CODE);
}
}else{
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST_CODE&& resultCode == RESULT_OK && data != null ) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
mImageView.setImageBitmap(bitmap);
}}
If you are asking "how do I get a full-resolution image?", supply
EXTRA_OUTPUT
on theACTION_IMAGE_CAPTURE
Intent
, then look at that location for the image whenonActivityResult()
is called withRESULT_OK
for your request.This sample app illustrates the technique, using
FileProvider
for better compatibility on Android 7.0+: