英文:
How to get specific number of images with Activity Results API
问题
我可以使用如下所示的 GetMultipleContents
来获取多张图片,我只想将所选图片的数量限制为例如 6 张。
getContent.launch("image/*");
ActivityResultLauncher<String> getContent = registerForActivityResult(new ActivityResultContracts.GetMultipleContents(),
new ActivityResultCallback<List<Uri>>() {
@Override
public void onActivityResult(List<Uri> result) {
// 在这里使用 URI
}
});
英文:
I can get multiple images using GetMultipleContents as shown below, I just want to limit the number of selected images to for example 6.
getContent.launch("image/*");
ActivityResultLauncher<String> getContent = registerForActivityResult(new ActivityResultContracts.GetMultipleContents(),
new ActivityResultCallback<List<Uri>>() {
@Override
public void onActivityResult(List<Uri> result) {
//Use URI here
}});
答案1
得分: 1
GetMultipleContents
使用 Intent.EXTRA_ALLOW_MULTIPLE
,这就是允许用户选择多张图片的原因。然而,并没有单独的额外参数来设置图片的最大数量 - 用户可以选择仅选择一张图片(当未设置该标志时,即使用 GetContent
),或者选择任意数量的图片而没有限制。
当然,你可以实际上只处理返回列表中的前6张图片。
英文:
GetMultipleContents
uses Intent.EXTRA_ALLOW_MULTIPLE
, which is what allows users to select multiple images. However, there is no separate extra that sets any maximum number of images - the user can either select only a single image (when the flag isn't set i.e., you're using GetContent
) or as many images as they want with no limit.
You can, of course, only actually process the first 6 images of the list you get back.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论