onActivityResult 用户取消 activity

onActivityResult user cancels the activity

我有一个 activity 请求获取图像

startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);

在我的 onActivityResult 上,如果用户在中间取消操作,我想处理这种情况。

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {

            Uri selectedImageUri = data.getData();
            String selectedImagePath = getPath(selectedImageUri);
            if (selectedImagePath != null) {
                 //do something
           }
            else
                Log.i("At the","selectedimagenull");
            }

        else
            Log.i("At the","SELECT PICTURENULL");
    }
}

但是如果用户取消操作,我将无处获取信息。我试过调试但它没有在任何地方捕获。这里有什么问题?

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {

            Uri selectedImageUri = data.getData();
            String selectedImagePath = getPath(selectedImageUri);
            if (selectedImagePath != null) {
                 //do something
           }
            else
                Log.i("At the","selectedimagenull");
            }

        else
            Log.i("At the","SELECT PICTURENULL");
    }
  else
  Log.i("At the","result not ok");  // User cancelled the activity
}