我正在寻找一种将android权限列表组合在一起的方法。 到目前为止,我已按照此Link between Android Permissions and Permission Groups链接进行了操作,但它提供了有关此处相关项目的信息https://developer.android.com/reference/android/Manifest.permission_group.html
但蓝牙,设置,套餐权限等项目未列出https://developer.android.com/reference/android/Manifest.permission.html。
我希望根据功能分类所有权限
Bluetooth(BLUETOOTH, BLUETOOTH_ADMIN, BLUETOOTH_PRIVILEGED)
等。
答案 0 :(得分:1)
我希望根据蓝牙(BLUETOOTH,BLUETOOTH_ADMIN,BLUETOOTH_PRIVILEGED)等功能对所有权限进行分类。
这是不可能的。应用可以定义自己的权限,这些权限不需要属于特定的权限组。
欢迎您call getPermissionInfo()
on a PackageManager
获取有关权限的信息,包括its group
。但是,您需要处理没有组的权限。
答案 1 :(得分:-1)
public void doCheckPermission() {
// The request code used in ActivityCompat.requestPermissions()
// and returned in the Activity's onRequestPermissionsResult()
int PERMISSION_ALL = 1;
String[] PERMISSIONS = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_NETWORK_STATE
};
if (!hasPermissions(NavigationDrawerActivity.this, PERMISSIONS)) {
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
}
public static boolean hasPermissions(Context context, String... permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case 1: {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && NavigationDrawerActivity.this != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(NavigationDrawerActivity.this, permission) == PackageManager.PERMISSION_GRANTED) {
// Toast.makeText(this, "Please give all permissions", Toast.LENGTH_SHORT).show();
Log.e("TAG", "onRequestPermissionsResult: given");
}
}
}
}
}
}
希望这会有所帮助!