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

Using Edit Text IME Option in Android App

An  Editor Info  is most useful class when you have to deal with any type of user input in your  Android application . For e.g. in login/registration/search operations we can use it for more accurate keyboard input. An editor info class describes several attributes for text editing object that an input method will be directly communicating with edit text contents. Several options which we can use with  EditText IMEOption  are as follows: IME_ACTION_DONE : This action performs a “done” operation for nothing to input and the IME will be closed. IME_ACTION_GO : This action performs a “go” operation to take the user to the target of the text user typed. IME_ACTION_NEXT : This action performs a “next” operation taking the user to next field that will accept text. IME_ACTION_NONE : There is no available action. IME_ACTION_PREVIOUS : This action performs to move to the previous field after “Next” operation is performed. IME_ACTION_SEARCH : This action perfor...

Sharing Simple Data In Android

As a  Android developer , you might want to integrate android apps with each other. Do you know how that functions?  Do you possess knowledge about the way in which they communicate?  If no, then for your reference, Android apps possess the ability to integrate as well as communicate with each other. There are ways in which simple data can be sent and received between applications. This can be done by using  Intent APIs  and the  ActionProvider object . In this article we will cover three ways to share simple data. Sending Simple Data to Other Apps Receiving Simple Data from Other Apps Adding an Easy Share Action 1. Sending Simple Data to Other Apps Sending & receiving data between apps is one of the most common uses of Intent. It allows for easy and quick sharing of information. One thumb rule to remember is that while constructing an Intent, it is imperative that you specify the action you want it to trigger. There are numerous actio...

Sharing Files With Android Apps

There are times when you have to share one or more files with other apps? Let’s take an example. You might have to send images to image editors. On the other hand, you might also Copy & Paste files between external storage? The best way, in this case, is to send the file’s content URI to the receiving app. You can allow the receiving app with temporary access permissions to the file’s content URI. Why is Content URI safe? The reason for this is that the content URI only applies to the app that receives the URI.  Once that has been done, it expires automatically.   There are ways of generating a file’s content URI.  One of them is the  getUriForFile()  method which is offered by Android FileProvider component. In this article, we will talk about ways of securing sharing files between apps by using content URIs and temporary permissions. The content URIs will be generated by using the  Android FileProvider component . 1) Set up file sharing...