Android PhotoPicker 返回 NULL URI。

huangapple go评论62阅读模式
英文:

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&lt;PickVisualMediaRequest&gt; pickImage = registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), uri -&gt; {

        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.

huangapple
  • 本文由 发表于 2023年6月1日 18:09:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76380833.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定