Android如何基于选择器意图中的用户操作请求权限
我无法根据用户在chooser intent中选择的内容请求用户权限。现在,我的程序是在选择器意图出现之前请求权限。在他们选择了意图之后,我如何以请求权限的方式实现。下面的代码是先请求照相机权限或存储权限,然后仅允许用户选择要从照相机或多媒体资料中拍照Android如何基于选择器意图中的用户操作请求权限,android,android-permissions,android-intent-chooser,Android,Android Permissions,Android Intent Chooser,我无法根据用户在chooser intent中选择的内容请求用户权限。现在,我的程序是在选择器意图出现之前请求权限。在他们选择了意图之后,我如何以请求权限的方式实现。下面的代码是先请求照相机权限或存储权限,然后仅允许用户选择要从照相机或多媒体资料中拍照 Dexter.checkPermissions(new MultiplePermissionsListener() { Intent chooserIntent = null; L
Dexter.checkPermissions(new MultiplePermissionsListener() {
Intent chooserIntent = null;
List<Intent> intentList = new ArrayList<>();
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
@Override
public void onPermissionsChecked(MultiplePermissionsReport report) {
List<PermissionGrantedResponse> list_GrantedPermission;
list_GrantedPermission = report.getGrantedPermissionResponses();
//check permission granted
if (report.areAllPermissionsGranted()){
intentList = addIntentsToList(mContext, intentList, takePhotoIntent);
intentList = addIntentsToList(mContext, intentList, pickIntent);
}
else if (list_GrantedPermission.size() > 0){
String grantedpermissionName = list_GrantedPermission.get(0).getPermissionName();
if (grantedpermissionName.equals(android.Manifest.permission.CAMERA))
intentList = addIntentsToList(mContext, intentList, takePhotoIntent);
else
intentList = addIntentsToList(mContext, intentList, pickIntent);
}
else {
}
//request a source
if (intentList.size() > 0) {
chooserIntent = Intent.createChooser(intentList.remove(intentList.size() - 1),
getString(R.string.message_select_source));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Parcelable[]{}));
startActivityForResult(chooserIntent, REQUEST_CODE_PICTURE);
}
if (report.isAnyPermissionPermanentlyDenied()){
final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext);
alertBuilder.setTitle(getString(R.string.message_permission_required));
alertBuilder.setCancelable(true);
alertBuilder.setMessage(getString(R.string.message_permission_required));
alertBuilder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
AlertDialog dialog = alertBuilder.create();
dialog.show();
}
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> permissions, PermissionToken token) {
token.continuePermissionRequest();
}
}, android.Manifest.permission.CAMERA, android.Manifest.permission.READ_EXTERNAL_STORAGE);
}
});
Dexter.checkPermissions(新的MultiplePermissionsListener(){
意向选择内容=null;
List intentList=new ArrayList();
Intent pickIntent=newintent(Intent.ACTION\u PICK,android.provider.MediaStore.Images.Media.EXTERNAL\u CONTENT\u URI);
Intent takePhotoIntent=新意图(MediaStore.ACTION\u IMAGE\u CAPTURE);
@凌驾
已检查许可证上的公共无效(多个许可证报告){
列表\u授予的权限;
list_GrantedPermission=report.getGrantedPermissionResponses();
//检查已授予的权限
if(report.areAllPermissionsGranted()){
意向列表=附加内容列表(mContext、意向列表、takePhotoIntent);
intentList=附加内容列表(mContext、intentList、PICKTENT);
}
else if(列出\u授予的权限.size()>0){
String grantedpermissionName=列表_GrantedPermission.get(0).getPermissionName();
if(grantedpermissionName.equals(android.Manifest.permission.CAMERA))
意向列表=附加内容列表(mContext、意向列表、takePhotoIntent);
其他的
intentList=附加内容列表(mContext、intentList、PICKTENT);
}
否则{
}
//请求消息来源
如果(intentList.size()>0){
chooserentent=Intent.createChooser(intentList.remove(intentList.size()-1),
getString(R.string.message_select_source));
选择content.putExtra(Intent.EXTRA_INITIAL_INTENTS,intentList.toArray(新包裹[]{}));
startActivityForResult(选择内容、请求代码和图片);
}
if(report.isAnyPermissionPermanentlyDenied()){
最终AlertDialog.Builder alertBuilder=新建AlertDialog.Builder(mContext);
alertBuilder.setTitle(getString(需要R.string.message_权限));
alertBuilder.setCancelable(真);
alertBuilder.setMessage(getString(R.string.message_权限_必需));
alertBuilder.setPositiveButton(getString(R.string.ok),新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){
dialog.dismise();
}
});
AlertDialog=alertBuilder.create();
dialog.show();
}
}
@凌驾
public void onPermissionRationalAlleshouldbeshown(列出权限、PermissionToken令牌){
token.continuePermissionRequest();
}
},android.Manifest.permission.CAMERA,android.Manifest.permission.READ\u外部存储);
}
});
我建议您看看关于拍照或拍照权限的答案
还有,这是一种简单的拍照方式。我建议您看看关于拍照或拍照权限的答案
此外,这是一种简单的拍照方式。使用这些意图不需要相机或存储许可。@jing你有这个问题的解决方案吗?@nitipatel很遗憾,我没有解决方案。您有解决方案吗?@jing如果您仍在寻找解决方案,您可以尝试此解决方案:您不需要相机或存储许可来使用这些意图。@jing您有这个问题的解决方案吗?@nitipatel不幸的是,我没有解决方案。你有解决方案吗?@jing如果你还在寻找解决方案,你可以试试这个解决方案: