Request permissions by java in Android version 23+
In android with version >= 23, you need to request some permissions in java code. To register some permissions, follow these steps:
- Step 1: Declare variables
private List<String> permissions; private static final int REQUEST_PERMISSION_RESULT = 0xFF;
- Step 2: Implement CheckPermission() function
private boolean CheckPermission() { permissions = new ArrayList<String>(); if (Build.VERSION.SDK_INT >= 23) { int hasPermission; hasPermission = checkSelfPermission(Manifest.permission.CAMERA); if (hasPermission != PackageManager.PERMISSION_GRANTED) permissions.add(Manifest.permission.CAMERA); hasPermission = checkSelfPermission(Manifest.permission.RECORD_AUDIO); if (hasPermission != PackageManager.PERMISSION_GRANTED) permissions.add(Manifest.permission.RECORD_AUDIO); } if (permissions.isEmpty()) return true; return false; }
- Step 3: Request permissions
if (!CheckPermission()){ if (Build.VERSION.SDK_INT >= 23){ requestPermissions( permissions.toArray(new String[permissions.size()]), REQUEST_PERMISSION_RESULT ); } }
That is it. And if you have some questions, feel free to ask me.
LP Devs
Tweet
Google