【发布时间】:2020-01-01 15:53:31
【问题描述】:
我正在尝试创建一个意图选择器来编辑“个人资料图片”,具有以下选项: 1. 相机 2.画廊 3. 删除图片
根据用户提供的权限,我将 cameraIntent 和 galleryIntent 添加到我添加到选择器的意图列表中。 但是,如果用户同时拒绝相机和图库权限,选择器会自动退回到选项 3,删除图像,这不是我想要的。
public Intent getImageChooserIntent(){
Intent galleryIntent = getGalleryIntent();
Intent cameraIntent = getCameraIntent();
Intent imageSourceChooser = Intent.createChooser(new Intent(), "Select Source");
List<Intent> intentList = new ArrayList<>();
if (galleryIntent != null) {
intentList.add(galleryIntent);
}
if (cameraIntent != null) {
intentList.add(cameraIntent);
}
intentList.add(new Intent(context, DeleteImageActivity.class));
imageSourceChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Intent[0]));
return imageSourceChooser;
}
如果用户拒绝相机和图库的权限,我希望提示显示一个只有一个选项的选择器 - “删除图像”。
【问题讨论】:
标签: android android-studio android-intent android-camera-intent