Reputation: 1005
I got stuck on an app when I tried to take a photo and store it in external storage. The camera intent worked but I couldn't confirm the captured image. Then I changed the onActivityResult to the following to monitor the resultCode. Touching the confirm button never logs anything. Touching the cancel button though logs both the expected logs.
private static final int TAKE_PHOTO_CODE = 2;
private File destination;
takePhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
destination = new File(Environment
.getExternalStorageDirectory(), "name");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(destination));
intent.putExtra("return-data", true);
startActivityForResult(intent, TAKE_PHOTO_CODE);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("Test", "App is inside onActivityResult");
Log.d("Test", String.valueOf(resultCode));
}
Edit : I believe I've properly given all the required permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"
android:required="true" />
Upvotes: 3
Views: 1619
Reputation: 13647
Is the "onActivityResult(int requestCode, int resultCode, Intent data)" defined in a Fragment or in an Activity?
...if it's in the Fragment, please add logs to the corresponding method in the Activity, sometimes it bring surprises like this.
the other possibility is that the camera is failing to write on the provided path..the "destination = new File(Environment .getExternalStorageDirectory(), "name");" ...ensure it is created and properly accessible.
Upvotes: 2