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

标签 android camera nullpointerexception

照片捕获 Intent 仅在三星手机上导致 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 - 照片捕获 Intent 仅在三星手机上导致 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7031374/

相关文章:

java - 如何在switch中使用String?

android - 带有 "activatedBackgroundIndicator"抽屉导航的所选项目的自定义背景颜色

android - 使用 ImageView 作为 Android 布局的背景

android - 房间: Cannot access database on the main thread *but*

java - 我如何在LWJGL中看到 "Jump"?

android - 为什么 findViewById 对于 CardView 返回 null?

android - 什么进入源代码管理?

c - 如何避免不支持的帧速率错误?

c# - ASP.Net 实时流式传输 IP 摄像机视频和音频

java - PreferenceFragment.findPreference 总是返回 NULL