startActivityForResult返回数据null

时间:2016-08-16 11:48:13

标签: android camera startactivityforresult

我尝试从相机发送图片到我的活动。我从startActivityForResult致电adapter,如下所示:

photo.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        dialog.dismiss();
        mActivity.dispatchTakePictureIntent(part.getId());
    }
});

这是Activity上的方法:

public void dispatchTakePictureIntent(String id) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File

        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.example.eltegps011.eltegps.fileprovider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            takePictureIntent.putExtra("Id",id);

            startActivityForResult(takePictureIntent, CAM_REQUEST);
        }
    }
}

这是我的onActivityResult()

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == 2) {
        part = (Part) data.getSerializableExtra("Part");
        Log.e(TAG, "onActivityResult: ");

}if(requestCode == 1313) {
    Bitmap thumbnail = (Bitmap)data.getExtras().get("data");
    String id = data.getStringExtra("Id");
    Log.e(TAG, "onActivityResult: " + id);
}

但是,Bitmap thumbnail = (Bitmap)data.getExtras().get("data")null resultCode始终为-1 。看起来意图无法到达activity。知道为什么吗?

0 个答案:

没有答案