从相机拍照时,Activity.RESULT_OK始终返回-1

时间:2018-01-05 10:53:04

标签: android android-camera

我正试图从相机拍照。 onActivityResult Activity.RESULT_OK始终返回-1。

这是我的代码

final int REQUEST_CAMERA = 1;

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, REQUEST_CAMERA);


  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
     //this condition always false
    if (requestCode == Activity.RESULT_OK) {//here Activity.RESULT_OK always return -1 

        if (requestCode == REQUEST_CAMERA) {

            Bundle bundle = data.getExtras();
            Bitmap btm = (Bitmap) bundle.get("data");              
            _ivDoc.setImageBitmap(btm);
        } 

    }
}

2 个答案:

答案 0 :(得分:1)

是的,因为它的常数值是-1。

RESULT_OK
added in API level 1
int RESULT_OK
Standard activity result: operation succeeded.

Constant Value: -1 (0xffffffff)

并且您需要检查resultCode而不是OK Result的请求代码。

答案 1 :(得分:0)

替换

if (requestCode == Activity.RESULT_OK)

if (resultCode == Activity.RESULT_OK)