Android requires user to enable permissions for my app that are already requested in manifest

13,730

Solution 1

Location and Bluetooth are two different things.

You don't need to request permission to access Bluetooth as it is a normal permission, but you do need to request permission for Location as it is a dangerous permission.

You can find a list of all permissions that must be requested on runtime here.

Solution 2

From the official documentation.

System permissions are divided into two categories, normal and dangerous:

  • Normal permissions do not directly risk the user's privacy. If your app lists a normal permission in its manifest, the system grants the
    permission automatically.
  • Dangerous permissions can give the app access to the user's confidential data. If your app lists a normal permission in its
    manifest, the system grants the permission automatically. If you
    list a dangerous permission, the user has to explicitly give
    approval to your app.

And

  • If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your
    manifest, the user has to grant the permission when they install the
    app; if they do not grant the permission, the system does not install the app at all.
  • If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.

So, most likely you are testiong your app on device or emulator running API 23+ and have a request to location of the device.

Location permission is a dangerous one, so in Android 6.0 or higher user is forsed to allow location access manually. For this you have to add dangerous permissions programmatically. Take a look here for the good instruction for this.

P.S. To find out, which permissions are dangerous, and wich are normal, look here.

Solution 3

Certain permissions are classified as dangerous and they need to be asked for in runtime.

ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.READ_CONTACTS},
            MY_PERMISSIONS_REQUEST_READ_CONTACTS);

Replace the READ_CONTACTS permission with location permission

Share:
13,730
petehallw
Author by

petehallw

Taught myself Java with the Swing framework and Android development after some OOP experience with C++. I'm currently learning design patterns and web development technologies such as HTML, CSS and JavaScript/JQuery/AJAX.

Updated on June 04, 2022

Comments

  • petehallw
    petehallw almost 2 years

    The application I am developing uses Bluetooth and Storage permissions, therefore my AndroidManifest.xml contains the following.

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"></uses-permission>
    <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"></uses-permission>
    

    However, when the app is installed, upon scanning for Bluetooth devices nothing is found until I manually switch on permission for Location in my device settings (Settings -> Apps -> [My App] -> Permissions). I have read somewhere that this permission is required for Android 6.0 (maybe 7.0) and above if you want to use the Bluetooth, but why is it not enabled upon installation with these permissions in the manifest file? Have I missed one out?