Axelle
Axelle

Reputation: 472

MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION permission android not recognised in code

We are currently trying to request GPS permissions from an android phone so that we can show the current location on a Google Map. We have included this manifest, outside of application tags, under the manifest tag:

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

Here is the part of our code that is not working, it is not recognising MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION:

 if (ActivityCompat.checkSelfPermission(this,
            android.Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                android.Manifest.permission.ACCESS_FINE_LOCATION)) {
            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }

We have also included "import android.Manifest".

Thanks in advance!

Upvotes: 2

Views: 5095

Answers (0)

Related Questions