照片捕获意图仅在Samsung手机上导致NullPointerException.
下面的实现.
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); } }
解决方法
我发现一个修复(不是我的工作),使其适用于三星设备.有解释的博客可以找到
here.
但是,在非三星手机上使用此修复会返回错误的图像,因此我将使用
if(imageURI != null) { // do it the normal way else { // do it the "Samsung" way }