Skip to main content

Runtime Requesting Permissions in Android

Problem Description

Before android marshmallow users have to grant all permissions when they install the application. But with recent release of Android OS 6.0 (Marshmallow), users can grant permissions to app while the app is running. This approach streamlines the app install process, since the user does not need to grant permissions when they install the app.
System permissions are divided into two categories,

1) Normal Permissions

  • Normal permission do not directly risk the user’s privacy.
  • If you have declare normal permissions in your manifiest, the system will grant your permissions automatically.
  • Some of the normal permissions are,
    • ACCESS_NETWORK_STATE
    • ACCESS_NOTIFICATION_POLICY
    • ACCESS_WIFI_STATE
    • BLUETOOTH
    • INTERNET
    • SET_TIME_ZONE
    • SET_WALLPAPER
    • VIBRATE
    • REQUEST_INSTALL_PACKAGES

2) Dangerous Permissions

  • If you have declared dangerous permissions in your manifiest, the user have to explicitly give approval to your app.
  • Here is the list of some of the dangerous permissions,
    • READ_EXTERNAL_STORAGE
    • WRITE_EXTERNAL_STORAGE
    • READ_CONTACTS
    • WRITE_CONTACTS
    • ACCESS_FINE_LOCATION
    • ACCESS_COARSE_LOCATION
    • READ_PHONE_STATE
    • CALL_PHONE
    • READ_CALL_LOG
    • WRITE_CALL_LOG
    • GET_ACCOUNTS
    • RECORD_AUDIO
    • SEND_SMS
    • RECEIVE_SMS
    • READ_SMS
    • RECEIVE_WAP_PUSH
    • RECEIVE_MMS
If you are running your android app on the device having Android 5.1 or lower and dangerous permissions are listed in your manifest, then the user have to grant all the permissions when installing the application. If the android app user do not grant those permissions then the user will not be able to install the application.

Solution

This solution is workable only for the devices running Android 6.0 (Marshmallow) as Android 6.0 allows the users to allow or deny the permissions separately. So if we have listed dangerous permissions in our manifest, then ideally it must request each permission it needs while the app is running. So if any user denies any permission, then the app should still run without any issues.
Here’s the code snippets to request such permissions at runtime.
Here’s the code snippets to request such permissions at runtime.

Comments

Popular posts from this blog

Handle Scrollable Views or Controls in another Scrollview in Android

In life of any Android developer, there are times when there is a requirement in the application to use one scrollable control inside another scrollable control. In such cases, the scrolling functionality of one or all scrollable controls gets enabled and the Android application cannot identify that scroll event of which control is to be handled first. Here, UI may get stuck in some scenarios. The ideal behavior expected is when the user touches the parent scroll view, only the parent view’s scroll event is called and when the user scrolls the child scroll view, the child view’s scroll event is called. In our standard Android application development and implementation process it does not happen when we add scrollable control in another scrollable control. Below is the solution to handle the scroll event of both the controls without any glitch. Example We have a layout that has a ScrollView as parent layout and it contains some TextViews, ImageViews and ListView as child control...
Android Push Notification Using Firebase Cloud Messaging In this tutorial, I’m gonna show you how to use the push notifications in your android applications. Before the Google I/O 2016 , we were using the Google Cloud Messaging service (GCM) to send the data from the server to the clients or the android power devices but in I/O 2016, Google introduced the Firebase Cloud Messaging which is a good alternative and easier to implement. Steps to implement FireBase push notification in Android 1: Import the code of FCM   https://drive.google.com/a/edreamz.in/file/d/0B1L0RecNhNk9UDhhOXRZQjJYU0k/view?usp=sharing 2: go to    https://console.firebase.google.com/  and create a new project. 4: Now put your app name and select your country. 5: Now click on Add Firebase to Your Android App. 6: Now you have to enter your projects package name and click on ADD APP. 7:After clicking add app you will get google-services.json fil...
Android Push Notification Using Firebase Cloud Messaging In this tutorial, I’m gonna show you how to use the push notifications in your android applications. Before the Google I/O 2016 , we were using the Google Cloud Messaging service (GCM) to send the data from the server to the clients or the android power devices but in I/O 2016, Google introduced the Firebase Cloud Messaging which is a good alternative and easier to implement. Steps to implement FireBase push notification in Android 1: Import the code of FCM   https://drive.google.com/a/edreamz.in/file/d/0B1L0RecNhNk9UDhhOXRZQjJYU0k/view?usp=sharing 2: go to    https://console.firebase.google.com/  and create a new project. 4: Now put your app name and select your country. 5: Now click on Add Firebase to Your Android App. 6: Now you have to enter your projects package name and click on ADD APP. 7:After clicking add app you will get google-services.json fil...