Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Photo capture Intent causes NullPointerException on Samsung phones only

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);
    }
}
like image 224
Oh Danny Boy Avatar asked Aug 11 '11 19:08

Oh Danny Boy


Video Answer


1 Answers

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

like image 142
Shahzad Imam Avatar answered Nov 15 '22 16:11

Shahzad Imam