Android 如何知道你所采取的行动的意图

Android 如何知道你所采取的行动的意图,android,android-intent,Android,Android Intent,以下代码启动gallery以从中选择图像: Intent choosePictureIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(choosePictureIntent, 1); 现在,我的问题是如何在onResultActivity()方法中知道意图返回时没有选择任何内容?(即用户没有从

以下代码启动gallery以从中选择图像:

Intent choosePictureIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(choosePictureIntent, 1);
现在,我的问题是如何在
onResultActivity()
方法中知道意图返回时没有选择任何内容?(即用户没有从“多媒体资料”中选择任何图像,只是点击了“取消”按钮)

我正在使用下面的代码,但它不能帮助我完成任务

Uri imageUriForGallery = intent.getData();
if(imageUriForGallery == null || imageUriForGallery.toString() == null) {
    Toast.makeText(this, "You didn't choose an image", Toast.LENGTH_LONG).show();
        break;
}
当用户没有从gallery中选择图像,只需点击gallery上的“取消”按钮,我的应用程序就会崩溃

现在,我的问题是如何在
onResultActivity()
方法中知道意图返回时没有选择任何内容


将在第二个参数中调用您的参数。

非常感谢!如果你也能解决这个问题,我会很高兴的()