11

Photo capture Intent causes NullPointerException on Samsung phones only.

Implementation below.

final Button capture = (Button)findViewById(R.id.capture_button);
capture.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

    }
});


protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_PIC_REQUEST) {  

        Bitmap thumbnail = (Bitmap)data.getExtras().get("data");
        ImageView image = (ImageView)findViewById(R.id.photoResultView);
        image.setImageBitmap(thumbnail);
    }
}
Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
Oh Danny Boy
  • 4,857
  • 8
  • 56
  • 88

4 Answers4

13

I found a fix (not my work) that makes it work for Samsung devices. The blog with explanation can be found here.

However, using this fix on non-Samsung phones returns the wrong image, so I would use an

if(imageURI != null) {
    // do it the normal way
else {
    // do it the "Samsung" way
}
Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
Ashterothi
  • 3,282
  • 1
  • 21
  • 35
  • 4
    as @Pyrodante suggested "However, using this fix on non-Samsung phones returns the wrong image, so I would use an " could any one please post the complete code , which should work on both samsung and non samsung's – LMK Nov 20 '13 at 11:41
4

Just got the same issue on a Samsung S4 and found out that adding configChanges to the AndroidManifest.xml solved the problem:

<activity
    android:name=".YourActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:screenOrientation="portrait" >
</activity>
Janine Kroser
  • 444
  • 2
  • 6
  • 23
3

you can check a little simple way over here to get Uri.

Get camera capture image path in android

calling camera

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(Intent.createChooser(cameraIntent,"Select Picture"), CAMERA_PIC_REQUEST1);

on result activity

final ContentResolver cr = getContentResolver();     
final String[] p1 = new String[] {
    MediaStore.Images.ImageColumns._ID,
    MediaStore.Images.ImageColumns.DATE_TAKEN
};
Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");      
if ( c1.moveToFirst() ) {
    String uristringpic = "content://media/external/images/media/" +c1.getInt(0);
    Uri newuri = Uri.parse(uristringpic);
    Log.i("TAG", "newuri   "+newuri);                    
}
c1.close();
}

Then you can get Uri path capture image

Get camera capture image path in android

dakshbhatt21
  • 3,558
  • 3
  • 31
  • 40
Shahzad Imam
  • 2,030
  • 2
  • 26
  • 45
-2

Get camera capture image path in android

calling camera

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(Intent.createChooser(cameraIntent,"Select Picture"), CAMERA_PIC_REQUEST1);

on result activity

final ContentResolver cr = getContentResolver();     
final String[] p1 = new String[] {
    MediaStore.Images.ImageColumns._ID,
    MediaStore.Images.ImageColumns.DATE_TAKEN
};

Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");      
if ( c1.moveToFirst() ) {
    String uristringpic = "content://media/external/images/media/" +c1.getInt(0);
    Uri newuri = Uri.parse(uristringpic);
    Log.i("TAG", "newuri   "+newuri);
}
c1.close();

then u can get Uri path capture image

(source)

biegleux
  • 13,179
  • 11
  • 45
  • 52
  • 1
    Lone link is [considered a poor answer](http://stackoverflow.com/faq#deletion) since it is meaningless by itself and target resource is not guaranteed to be alive in the future. Please try to include at least summary of information you are linking to. – j0k Sep 17 '12 at 12:34