Get all permissions on app install in API targeting 26

In Android API version 22 and earlier, the system will get all permissions during installation. From API 23 (Marshmallow), the system asks for permission at runtime (when the app actually tries to use the function). This doesn't work very well for some reason.

  • The developer has to write 2 different (1 - if the user grants permission, 2. if the user denies permission) code streams all the time.

  • When asked for permission, Android has full control to show what text will be displayed in the permission dialog and asks the user to click Yes or No. Sometimes the text displayed in the permission dialog is inappropriate.

  • When we request multiple permissions and if one of the permissions is denied, the app crashes due to an Android code error. This is an issue with API 23, 24 and 25. I think this is fixed in 26.

Problems arising in our application,

Example 1: For security reasons, we are trying to get the device ID, but when we ask for permission, Android shows a message like Allow MyApp to manage phone calls . We have nothing to do with phone calls, the message is not suitable for accessing the device ID. This reduces user registration (registration) in the app and the marketing team is very worrying.

Example 2: We have a lot of web views and try to use offline storage and cache as much as possible for the best user experience, but users are denying permission because the Android permission dialog shows " Allow MyApp to access storage files .

So the question is, Is there anyway to get all permissions during app install (e.g. API v22 and earlier) in newer API versions (23 and above) and not ask at runtime?

+3


source to share


2 answers


First, a runtime query is best practice and this is an explanation from Google

In some cases, you can help the user understand why your application needs permission. For example, if a user launches a photo app, the user probably won't be surprised that the app asks for permission to use the camera, but the user may not understand why the app wants to access the user's location or contacts. Before asking for permission, you should consider providing an explanation to the user. Keep in mind that you don't want to overwhelm the user with explanations; if you provide too many explanations, the user may find that the application is frustrating and uninstalls it.

One approach you can use is to provide an explanation only if the user has already denied this permission request. If the user continues to use functionality that requires permission, but continues to deny the permission request, it probably indicates that the user does not understand why the application needs permission to provide that functionality. In such a situation, it is probably a good idea to show an explanation.

To help find situations where the user might need an explanation, Android provides a utiltity method, shouldShowRequestPermissionRationale (). This method returns true if the application has previously requested this permission and the user has denied the request.

Note. If the user has denied the permission request in the past and selected the Do not ask again option in the permission request system dialog box, this method returns false. The method also returns false if the device policy prevents the application from having this permission.

So, in your situation, if you read the documentation carefully, you can ask for all permissions once during installation. In file build.gradle

(application) set targetSdkVersion

to api level below 23. For example:



android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "vn.yourpackage.name"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

      

}

+3


source


When we request multiple permissions and if one of the permissions is denied, the app crashes due to an Android code error.

This is not true. Your application should be able to handle this situation.

Is there a way to get all permissions on app install (e.g. API v22 and earlier) in newer API versions (23 and above) instead of being asked at runtime?



No, when your application targets API> = 23, then you must request permissions at runtime.

For the first example, I suggest you read the official documentation of the Best Practice Guidelines for Applications . He offers helpful advice that can help you.

As for the second example, the best thing you can do is explain to the user why the application needs permissions. You can read it here .

+2


source







All Articles