Android Studio asking for permission even though it is given in android manifest

Regnav

my android manifest looks like this:

<?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.regnav.stilla" >

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity android:name=".MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

When I try to use the permission which is in the Android Manifest like this:

    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    Location location = locationManager.getLastKnownLocation(provider);

It will tell me that I need to do a permission check like so:

if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    public void requestPermissions(@NonNull String[] permissions, int requestCode)
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for Activity#requestPermissions for more details.
            return;
        }

I think this is strange as my android manifest already gives me permission to do this.. Am I doing something wrong?

I am editting the Android manifest in location:

Stilla/app/src/main/AndroidManifest.xml

What Am I doing wrong?

Sagar D

If you are on Android 6.0, checking whether you have a specific permission at any given point in the lifecycle of the app is mandatory. It is so because the user can revoke any single permission anytime he feels so and your app is NOT notified about this revoken permission.

Hence, before using any API which needs a permission, you should check whether you have by using the snippet you have posted. This is true even if you have that permission in your manifest. Have a look at the developer article

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Manifest permission in Android Studio

From Dev

Ionic App on Android Marshmallow repeatedly asking for permission, even after granting it

From Dev

Android Contact permission denied even if it is declared on Android manifest

From Dev

Permission for sockets - android manifest

From Dev

java.lang.SecurityException: Permission denied (missing INTERNET permission?) even with adding this permission in android manifest

From Dev

(Android Studio Speech Recognizer) I'm getting error 9 (insufficient Privileges) even though I have given it RECORD_AUDIO and INTERNET

From Java

Android "gps requires ACCESS_FINE_LOCATION" error, even though my manifest file contains this

From Dev

Manifest Merge in Android Studio

From Dev

Android studio manifest issue

From Dev

Android - Asking permission to see user location

From Dev

Android contacts permission granted without asking at runtime

From Dev

Android Studio is adding me android.permission.USE_CREDENTIALS on my manifest

From Dev

No resource found that matches the given name: attr android:actionModeShareDrawable even though I'm using appcompat 20

From Dev

Android security exception for permission listed in manifest file

From Dev

Android Manifest Automatically Generating Invalid Permission

From Dev

Android remove duplicate user permission in manifest file

From Dev

android manifest permission don't work

From Dev

ActivityNotFoundException even though it is declared in Manifest

From Dev

Android studio Dangerous permission

From Dev

App is asking for permission i have not added in manifest

From Dev

Manifest Merging Failed: Android Studio

From Dev

Android says no such file or folder even though it's there

From Dev

Android - Socket Connected even though it cannot

From Dev

Need to enter keystore details manually in Android Studio even though they exist in build.gradle

From Dev

Asking permission on Android M when Min SDK is L

From Dev

Android: get current device location without asking permission at run time

From Dev

Application Name not visible when asking for permission in android 6.0 during runtime

From Dev

Android 6.0 - Download file to external storage without asking for permission

From Dev

Android: Unable to instantiate activity though the class is present and referenced correctly in manifest

Related Related

  1. 1

    Manifest permission in Android Studio

  2. 2

    Ionic App on Android Marshmallow repeatedly asking for permission, even after granting it

  3. 3

    Android Contact permission denied even if it is declared on Android manifest

  4. 4

    Permission for sockets - android manifest

  5. 5

    java.lang.SecurityException: Permission denied (missing INTERNET permission?) even with adding this permission in android manifest

  6. 6

    (Android Studio Speech Recognizer) I'm getting error 9 (insufficient Privileges) even though I have given it RECORD_AUDIO and INTERNET

  7. 7

    Android "gps requires ACCESS_FINE_LOCATION" error, even though my manifest file contains this

  8. 8

    Manifest Merge in Android Studio

  9. 9

    Android studio manifest issue

  10. 10

    Android - Asking permission to see user location

  11. 11

    Android contacts permission granted without asking at runtime

  12. 12

    Android Studio is adding me android.permission.USE_CREDENTIALS on my manifest

  13. 13

    No resource found that matches the given name: attr android:actionModeShareDrawable even though I'm using appcompat 20

  14. 14

    Android security exception for permission listed in manifest file

  15. 15

    Android Manifest Automatically Generating Invalid Permission

  16. 16

    Android remove duplicate user permission in manifest file

  17. 17

    android manifest permission don't work

  18. 18

    ActivityNotFoundException even though it is declared in Manifest

  19. 19

    Android studio Dangerous permission

  20. 20

    App is asking for permission i have not added in manifest

  21. 21

    Manifest Merging Failed: Android Studio

  22. 22

    Android says no such file or folder even though it's there

  23. 23

    Android - Socket Connected even though it cannot

  24. 24

    Need to enter keystore details manually in Android Studio even though they exist in build.gradle

  25. 25

    Asking permission on Android M when Min SDK is L

  26. 26

    Android: get current device location without asking permission at run time

  27. 27

    Application Name not visible when asking for permission in android 6.0 during runtime

  28. 28

    Android 6.0 - Download file to external storage without asking for permission

  29. 29

    Android: Unable to instantiate activity though the class is present and referenced correctly in manifest

HotTag

Archive