照片拍摄意图导致NullPointerException异常上只有三星手机 [英] Photo capture Intent causes NullPointerException on Samsung phones only

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

问题描述

照片拍摄意图引起 NullPointerException异常三星手机只。

下面的实现。

 最后按钮捕捉=(按钮)findViewById(R.id.capture_button);
capture.setOnClickListener(新OnClickListener(){

    @覆盖
    公共无效的onClick(视图v){
        // TODO自动生成方法存根
        意图cameraIntent =新的意图(MediaStore.ACTION_IM​​AGE_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(缩略图);
    }
}
 

解决方案

我发现了一个修复(不是我的作品),它使三星设备正常工作。与解释的博客可以发现<一href="http://kevinpotgieter.word$p$pss.com/2011/03/30/null-intent-passed-back-on-samsung-galaxy-tab/">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
}

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆