How to Handle Runtime Permissions in Android

How to Handle Runtime Permissions in Android


Google changed the way of permissions that applications handle from Android M or Marshmallow or Android 6.0. An Application needs permissions to use device's Hardware or Software Resources like Storage,Internet,Gallery,GPS or Network State etc.
In the earlier Android versions till Android 5.1.1 Lollipop, we only mention the permissions in the AndroidManifest.xml file. At that time we don't need to check permissions every time.
But from Android Marshmallow, we need to check for permissions every time app runs.
We declare all permissions in the AndroidManifest.xml file that need to access at runtime when the app runs.

Permission Types:

     1.Normal Permissions
     2.Dangerous Permissions

Normal Permissions 
                            that do not affect user's privacy directly like changing timezone or change WiFi state. These permissions are directly given by system at installation time. It only needs to be declared in the AndroidManifest.xml file and not to be checked at runtime. For Example:

<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

Dangerous Permissions
                           that want to access sensitive user data like access to camera to take picture or video recording etc. These permissions need to be checked at runtime. For Example:


<uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.CALL_PHONE" /><uses-permission android:name="android.permission.SEND_SMS" /><uses-permission android:name="android.permission.READ_PHONE_STATE" />


How to Handle Permissions:

Step 1.

 First make an interface and Write permission code and make a list of permissions like below:


Step 2.

 In the Main Activity check Build SDK version and request permissions by writing a method like below:


Step 3.

 Now getting the result of permission request by overriding this method.

Step 4.

 Now check the permission is granted or not while running the app.


Comments

Post a Comment

Popular posts from this blog

How to make Gradient Background in Android Studio

Top 10 Wallpaper Android Apps

Blood Donors Using Firebase