英文:
Android PhotoPicker returns NULL URI
问题
ActivityResultLauncher<PickVisualMediaRequest> pickImage = registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), uri -> {
if(uri==null) {
//这里始终为NULL
} else {
//从未到达
}
});
pickImage.launch(new PickVisualMediaRequest.Builder()
.setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
.build());
我已经在一个新项目中尝试了相同的代码,它返回了一个有效的URI。但是在我的项目中,PhotoPicker返回了一个NULL URI。有什么想法可能是问题吗?
英文:
ActivityResultLauncher<PickVisualMediaRequest> pickImage = registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), uri -> {
if(uri==null) {
//URI always NULL here
} else {
//Never reached
}
});
pickImage.launch(new PickVisualMediaRequest.Builder()
.setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
.build());
I have tried the same code in a new project and it is returning a valid URI. But PhotoPicker returns a NULL URI in my project. Any idea what could be the issue here?
答案1
得分: 0
PhotoPicker(或者通常的ActivityResultLauncher)似乎会在Activity中也重写了onActivityResult()的情况下失败。我将其移除后,现在PhotoPicker返回了一个有效的URI。
英文:
Apparently, PhotoPicker (or ActivityResultLauncher in general) fails if onActivityResult() is also Overridden in the Activity. I removed that and now PhotoPicker is returning a valid URI.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论