本文介绍了照片捕获意图仅在三星手机上导致 NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

照片捕获 Intent 仅在三星手机上导致 NullPointerException.

Photo capture Intent causes NullPointerException on Samsung phones only.

实现如下.

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
}

这篇关于照片捕获意图仅在三星手机上导致 NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-19 00:10