ACCESS_FINE_LOCATION AndroidManifest Permissions Not Being Granted

前端 未结 4 610
一个人的身影
一个人的身影 2020-12-15 19:59

I am trying to utilize GPS in Android (2.2 and 2.3) but am getting the following error when I try to use the LocationManager object:

WARN/System.err(522): java

相关标签:
4条回答
  • 2020-12-15 20:27

    You misspelled permission

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
    0 讨论(0)
  • 2020-12-15 20:28

    Compatible with all SDK versions (android.permission.ACCESS_FINE_LOCATION became dangerous permission in Android M and requires user to manually grant it).

    In Android versions below Android M ContextCompat.checkSelfPermission(...) always returns true if you add these permission(s) in AndroidManifest.xml)

    public void onSomeButtonClick() {
        ...
        if (!permissionsGranted()) {
            ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, 123);
        } else doLocationAccessRelatedJob();
        ...
    }
    
    private Boolean permissionsGranted() {
        return ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED);
    }
    
    @Override
    public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, @NonNull final int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == 123) {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission granted.
                doLocationAccessRelatedJob();
            } else {
                // User refused to grant permission. You can add AlertDialog here
                Toast.makeText(this, "You didn't give permission to access device location", Toast.LENGTH_LONG).show();
                startInstalledAppDetailsActivity();
            }
        }
    }
    
    private void startInstalledAppDetailsActivity() {
        Intent i = new Intent();
        i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        i.addCategory(Intent.CATEGORY_DEFAULT);
        i.setData(Uri.parse("package:" + getPackageName()));
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);
    }
    

    in AndroidManifest.xml:

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    
    0 讨论(0)
  • I was having the same problem and could not figure out what I was doing wrong. Turns out, the auto-complete for Android Studio was changing the text to either all caps or all lower case (depending on whether I typed in upper case or lower cast words before the auto-complete). The OS was not registering the name due to this issue and I would get the error regarding a missing permission. As stated above, ensure your permissions are labeled correctly:

    Correct:

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

    Incorrect:

    <uses-permission android:name="ANDROID.PERMISSION.ACCESS_FINE_LOCATION" />
    

    Incorrect:

    <uses-permission android:name="android.permission.access_fine_location" />
    

    Though this may seem trivial, its easy to overlook.

    If there is some setting to make permissions non-case-sensitive, please add a comment with the instructions. Thank you!

    0 讨论(0)
  • 2020-12-15 20:31

    just remove s from the permission you are using sss you have to use ss

    0 讨论(0)
提交回复
热议问题