我试图从onActivityResult(ActivityResult result)方法中获取意图 using
Intent intent = result.getData();但返回的结果意图是null?
我正在使用registerForActivityResult创建ActivityResultLauncher<Intent>来启动意图,如下面的代码所示
cLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent intent = result.getData();
Log.d(TAG,"intent: "+intent);
int id = intent.getIntExtra(buttonClicked,0);
Log.d(TAG,"id: "+id);
}
}
});
private void launchCamera(int id) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = BitmapUtils.createTempImageFile(this);
} catch (IOException ex) {
ex.printStackTrace();
}
if (photoFile != null) {
mTempPhotoPath = photoFile.getAbsolutePath();
Uri photoURI = FileProvider.getUriForFile(this,
FILE_PROVIDER_AUTHORITY,
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
takePictureIntent.putExtra(buttonClicked,id);
cLauncher.launch(takePictureIntent);
}
}
}