-3

I am looking for a way to group android permission list together. So far i have followed this Link between Android Permissions and Permission Groups link but it give information on related to items here https://developer.android.com/reference/android/Manifest.permission_group.html

But items such as Bluetooth, Settings, Package permissions are not listed https://developer.android.com/reference/android/Manifest.permission.html.

I wish to categorize all permissions based on feature like Bluetooth(BLUETOOTH, BLUETOOTH_ADMIN, BLUETOOTH_PRIVILEGED) etc.

Community
  • 1
  • 1
silentsudo
  • 6,730
  • 6
  • 39
  • 81

2 Answers2

1

I wish to categorize all permissions based on feature like Bluetooth(BLUETOOTH, BLUETOOTH_ADMIN, BLUETOOTH_PRIVILEGED) etc.

That is not going to be possible. Apps can define their own permissions, and those permissions do not need to belong to a specific permission group.

You are welcome to call getPermissionInfo() on a PackageManager to get information about a permission, including its group. However, you will need to cope with permissions that do not have a group.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • i agree, apps can have their custom permissions, i am looking to categorize the default one, of course custom permissions i can keep as others or by apps name. and yes call to get getPermissionsInfo and all is working as expected here https://gist.github.com/ashish29agre/93ed5f13f916048492e9aae4d8121ef0 – silentsudo Apr 25 '17 at 11:04
-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");
                        }
                    }
                }
            }
        }
    }

Hope this will help!

Akp
  • 259
  • 1
  • 9