In my app, I am using an intent to start the phone's camera, take a picture and save it locally on the phone. This is all working fine, however, once I press save (to save the picture) the the app quits and it takes me back to the home screen of my phone. I'm not sure what I'm missing so that after I press save, it goes back to my app rather than the home screen? Below is my code:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//other code, removed as its unrelated
btnAddExpense.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(context, "List Item Clicked.", Toast.LENGTH_LONG).show();
// create intent with ACTION_IMAGE_CAPTURE action
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// this part to save captured image on provided path
File file = new File(Environment.getExternalStorageDirectory(), "AutoTracker_" + System.currentTimeMillis() + ".jpg");
Uri photoPath = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoPath);
// start camera activity
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
});
return rowView;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
// Image captured and saved to fileUri specified in the Intent
Toast.makeText(context, "Image saved to:\n" + data.getData(), Toast.LENGTH_LONG).show();
} else if (resultCode == Activity.RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
}
if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
// Video captured and saved to fileUri specified in the Intent
Toast.makeText(context, "Video saved to:\n" + data.getData(), Toast.LENGTH_LONG).show();
} else if (resultCode == Activity.RESULT_CANCELED) {
// User cancelled the video capture
} else {
// Video capture failed, advise user
}
}
}
Thanks!