Kirankumar Dafda
Kirankumar Dafda

Reputation: 2384

React native current location asking for permission in AndroidManifiest.xml ACCESS_FINE_LOCATION, but already added

I have already added ACCESS_FINE_LOCATION but still getting error of

Looks like the app doesn't have the permission to access location. Add the following line to your app's AndroidManifest.xml: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

enter image description here

Here is my AndroidManifest.xml file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="22" />

Please Help.

Upvotes: 2

Views: 5581

Answers (2)

Goku
Goku

Reputation: 9692

You need to add ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permission in manifest

make sure you have added the permission in manifest file

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

if you are targetting android api 23 and above than you have to ask run-time permission

Because Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.

SAmple code

                 String permission = android.Manifest.permission.ACCESS_FINE_LOCATION;

 if (ActivityCompat.checkSelfPermission(SearchCityClass.this, permission)
                        != PackageManager.PERMISSION_GRANTED && ActivityCompat.
                        checkSelfPermission(SearchCityClass.this, android.Manifest.permission.ACCESS_COARSE_LOCATION)
                        != PackageManager.PERMISSION_GRANTED) {

                    Toast.makeText(SearchCityClass.this, "Permission not granted", Toast.LENGTH_SHORT).show();

                    ActivityCompat.requestPermissions(SearchCityClass.this, new String[]
                            {permission}, requestCode);

                } 

Upvotes: 2

Sunil Soni
Sunil Soni

Reputation: 443

On devices before SDK version 23, the permissions are automatically granted if they appear in the manifest, so check and the request should always be true.

If a user has previously turned off a permission that you prompt for, the OS will advise your app to show a rationale for needing the permission. The optional rationale argument will show a dialog prompt only if necessary - otherwise, the normal permission prompt will appear.

    import { PermissionsAndroid } from 'react-native';
    async function requestCameraPermission() {
    try {
          const granted = await PermissionsAndroid.request(
          PermissionsAndroid.ACCESS_FINE_LOCATION,
          {
          'title': 'Location Permission Permission',
           'message': 'App needs access to your Location ' +
               '.'
          }
          )
       if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        console.log("You can use the Location")
       } else {
         console.log("Location permission denied")
     }
} catch (err) {
console.warn(err)
}
}

Upvotes: 1

Related Questions