Articles → Android → Permissions In Android

Permissions In Android






Why Permission?





Categories Of Permission




  1. 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.
  2. Signature permissions - These are the permissions which a system grants during installation time.
  3. Dangerous permission - Those permissions which accesses user’s private information are dangerous permissions. For example, accessing the user contacts is dangerous permission.

Implementation




  1. Add uses-permission in android manifest. For example
  2. <uses-permission android:name="android.permission.CAMERA" />




  3. In onCreate method, write the following code
  4. 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




  1. Go to settings
  2. Go to App permissions
  3. Select app
  4. Select Camera
  5. Select the option ‘Ask’.
  6. Picture showing  setting the camera permission to ask
    Click to Enlarge



Output




Picture showing  the permission popup window in android application
Click to Enlarge


Call Back Method For Permissions




@Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
  super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}



Posted By  -  Karan Gupta
 
Posted On  -  Sunday, December 15, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250