This is weird. The following code was working a few weeks ago, and now it is not:
private void onClick()
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mOriginalUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"original" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
Log.d("path", mOriginalUri.getPath());
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mOriginalUri);
intent.putExtra("return-data", true);
startActivityForResult(intent, CAMERA_REQUEST);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch( requestCode )
{
case CAMERA_REQUEST:
if(resultCode == MainActivity.RESULT_OK)
Log.d("path", mOriginalUri.getPath());
break;
}
}
Somehow the camera capture activity is losing track of my Uri and setting it to null. I get a NPE when printing the path in the onActivityResult. How can I resolve this? I'm using Android 4.1.2 API 16 on a Galaxy Nexus.