android权限管理

https://github.com/yanzhenjie/AndPermission
If you are using the android support library:

implementation 'com.yanzhenjie.permission:support:2.0.1'
If you are using the android x library:

implementation 'com.yanzhenjie.permission:x:2.0.1'
直接用别人的库
AndPermission.with(this)
  .runtime()
  .permission(Permission.Group.STORAGE)
  .onGranted(permissions -> {
    // Storage permission are allowed.
  })
  .onDenied(permissions -> {
    // Storage permission are not allowed.
  })
  .start();动态申请权限



//申请wifi权限
 AndPermission.with(BindDeviceActivity.this)
                .permission(Permission.ACCESS_FINE_LOCATION, Permission.ACCESS_COARSE_LOCATION)
                .onGranted(permissions -> {
                    if(!isOPen(BindDeviceActivity.this)){
                        new MaterialAlertDialogBuilder(BindDeviceActivity.this)
                            .setTitle("提示")
                            .setMessage("请手动打开gprs定位服务")
                            .setPositiveButton("确定", (dialog,witch)->{
                                initAccess();
                            })
                            .setNegativeButton("取消",(dialog,witch)->{
                                startActivity(new Intent(this,MainActivity.class));
                            })
                            .show();
                    }
                })
                .onDenied(permissions -> {
                    new MaterialAlertDialogBuilder(BindDeviceActivity.this)
                            .setTitle("提示")
                            .setMessage("请给予wifi权限")
                            .setPositiveButton("确定", (dialog,witch)->{
                                initAccess();
                            })
                            .setNegativeButton("取消",(dialog,witch)->{
                              startActivity(new Intent(this,MainActivity.class));
                            })
                            .show();
                }).start();
    }

你可能感兴趣的:(android)