开发者

App crashes when trying to take a picture on different devices - Android

My app has enables the users to take a photo using the camera.

I've tested it on several devices(Nexus S,Nexus One, HTC Magic and Galaxy S). The app worked fine on the first 3 phones, but crashed with the Galaxy.

This is the code I wrote -

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "121.jpg");
values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");


imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);

startActivityForResult(cameraIntent, 2);  

And this is the OnActivityResult function -

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { 

        if (resultCode == RESULT_OK) {

                else if (requestCode == 2)
                {
                    sun=getRealPathFromURI(imageUri);
                    File f = new File(sun);
                    thePic.setImageBitmap(decodeFile(f));
                    }

        }
}

The resultCode is returned as 0(not RESU开发者_如何学运维LT_OK), and then the app crahses.

Thanks!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜