First I did look at other questions regarding this but they say to do what I am doing.
I am trying to launch the camera to take a picture like this
PackageManager pm = getPackageManager();
if(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)){
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File tempDir= new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "My App");
if(!tempDir.exists())
{
if(!tempDir.mkdir()){
Toast.makeText(this, "Please check SD card! Image shot is impossible!", Toast.LENGTH_SHORT).show();
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.US).format(new Date());
File mediaFile = new File(tempDir.getPath() + File.separator +
"IMG_"+ timeStamp + ".jpg");
photoUri = Uri.fromFile(mediaFile);
camera.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
startActivityForResult(camera, CAMERA_REQUEST);
}else{
Toast.makeText(this, "This device does not have a rear facing camera",Toast.LENGTH_SHORT).show();
}
but when it comes back to onActivityResult
the intent is null but the result is OK
. I can go to the directory on the device and see that it was correctly saved too.
If I take out camera.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
and just create a basic intent to launch the camera, the intent is not null on the return.
I would guess that photoUri
is still valid and safe to store since the image is in the directory but why is the intent null on the return when I supply the uri?