• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Camera : intent returns null

software

Lurker
I have an android application which contains multiple activities.

In one of them I'm using a button which will call the device camera :

Code:
public void onClick(View view) {
    Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(photoIntent, IMAGE_CAPTURE);
}
In the same activity I call the OnActivityResult method for the image result :

Code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == IMAGE_CAPTURE) {
        if (resultCode == RESULT_OK) {
            Bitmap image = (Bitmap) data.getExtras().get("data");
            ImageView imageview = (ImageView) findViewById(R.id.pic);
            imageview.setImageBitmap(image);}
        else if (resultCode == RESULT_CANCELED) 
            {Toast.makeText(this, "CANCELED ", Toast.LENGTH_LONG).show();}
    }
}

The problem is that the intent data is null and the OnActivityResult method turns directly to the (resultCode == RESULT_CANCELED) and the application returns to the previous avtivity.

How can I fix this issue and after calling the camera, the application returns to the current activity which contains an ImageView which will contains the picture taken?

Thanks
 
In my experience camera on android's is quite buggy + there are differences on how you handle onActivityResult intent on different devices.

You might want to try to set the the file name where the image will be saved. Some devices (older HTC models specifically, that I know) have this issue

URI pictureUri = Uri.fromFile(new File(<path to your file>));
camera.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);

you may also want to be careful about how streams are sent via intents vs Uri vs in some cases URL

Hope this helps some
 
Back
Top Bottom