android – 照片捕获意图仅在Samsung手机上导致NullPointerException

照片捕获意图仅在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
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...