由网友(別老在我心裏i)分享简介:照片拍摄意图引起 NullPointerException异常三星手机只。下面的实现。最后按钮捕捉=(按钮)findViewById(R.id.capture_button);capture.setOnClickListener(新OnClickListener(){@覆盖公共无效的onClick(视图v){// T...
照片拍摄意图
引起 NullPointerException异常
三星手机只。
下面的实现。
最后按钮捕捉=(按钮)findViewById(R.id.capture_button);
capture.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根
意图cameraIntent =新的意图(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,CAMERA_PIC_REQUEST);
}
});
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
如果(要求code == CAMERA_PIC_REQUEST){
。位图的缩略图=(位图)data.getExtras()获得(数据);
ImageView的形象=(ImageView的)findViewById(R.id.photoResultView);
image.setImageBitmap(缩略图);
}
}
解决方案
我发现了一个修复(不是我的作品),它使三星设备正常工作。与解释的博客可以发现here.
然而,使用非三星手机此修复程序返回错误的形象,所以我会用一个
如果(imageURI!= NULL){
//做正常的方式
其他 {
//做了三星的方式
}
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);
}
}
解决方案
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
}
相关推荐
最新文章