Articles → Android → Permissions In Android
Permissions In Android
Why Permission?
Categories Of Permission
- Normal permissions - Normal permissions are those where your application requests to access data outside application’s sandbox, but there is a little risk of privacy breach. For example, setting the timezone is normal permission.
- Signature permissions - These are the permissions which a system grants during installation time.
- Dangerous permission - Those permissions which accesses user’s private information are dangerous permissions. For example, accessing the user contacts is dangerous permission.
Implementation
- Add uses-permission in android manifest. For example
<uses-permission android:name="android.permission.CAMERA" />
- In onCreate method, write the following code
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[] {
Manifest.permission.CAMERA
}, 1);
}
Setting The App Permission
- Go to settings
- Go to App permissions
- Select app
- Select Camera
- Select the option ‘Ask’.
Click to Enlarge
Output
Click to Enlarge
Call Back Method For Permissions
@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}