I am developing an application where i need to have a dialog choose for uploading image from gallery or camera. I have found kind of solution here Dialog to pick image from
Just an advice when you call startActivityForResult()
to take a photo with camera:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(cameraIntent, REQUEST_CAMERA);
}
Notice that the startActivityForResult()
method is protected by a condition that calls resolveActivity()
, which returns the first activity component that can handle the intent. Performing this check is important because if you call startActivityForResult()
using an intent that no app can handle, your app will crash. So as long as the result is not null, it's safe to use the intent.