Missing permissions required by FusedLocationClient

Gavin Rook Source

I'm working on getting an app to get GPS location from a phone. I have added permissions to the XML for ACCESS_COURSE_LOCATION but it is still saying that I need permissions for that, even though the permission is already in the XML.

Here's my code:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.location.Location;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;


public final class MainActivity extends AppCompatActivity {
    public static final String TAG = "Kindness";

    private FusedLocationProviderClient mFusedLocationClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mFusedLocationClient = LocationServices.getFusedLocationProviderClient(
                this);

        mFusedLocationClient.getLastLocation().addOnSuccessListener(this,
                new OnSuccessListener<Location>() {
                    @Override
                    public void onSuccess(Location location) {
                        if (location != null) {

                        }
                    }
                });
    }


}

And here's the XML:

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

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/appName"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name="edu.byui.cit.kindness.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

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

</manifest>
javaandroidxmlsyntaxpermissions

Answers

answered 3 months ago pushasha #1

This is likely because location permissions are considered "dangerous" permissions by Android, and when your application's target SDK is 23 or greater, you are required to ask for "dangerous" permissions at runtime. Just adding them to the manifest does not work.

ActivityCompat.requestPermissions(this,
                arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION),
                REQUEST_CODE);

comments powered by Disqus