I need to click an image using the default camera app on an android device and get the path of the image just clicked. I have taken help from this post
And my code is as follows
public void MarkIn(View view) {
String fileName = "temp.jpg";
final int CAPTURE_PICTURE_INTENT = 1;
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intent, CAPTURE_PICTURE_INTENT);
String imagePath = capturedImageFilePath;
// .....some code.....
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = null;
cursor = getApplicationContext().getContentResolver().query(mCapturedImageURI, projection, null, null, null);
int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
capturedImageFilePath = cursor.getString(column_index_data);
}
}
The system isn't waiting for Activity to get completed. As my ...some code... in the above snippet is depenedent on the file path, I am getting null pointer exception.
How to make the code execution wait till the activity is completed.