FatUglyProud FatUglyProud - 3 months ago 58
Android Question

Cannot resolve symbol for permissions

I'm working on my first app in Android Studio which is using Google Maps. I'm trying to check the permissions in the MapsActivity but I'm getting 'Cannot resolve symbol 'ACCESS_FINE_LOCATION''.

I don't know why this is happening and I'm a bit out of my depth.

Here's the MapsActivity.java:

package com.example.i329968.mapstests;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
{

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap)
{
mMap = googleMap;

googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setIndoorEnabled(true);
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));

// mMap.setMyLocationEnabled(true);

if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
{
mMap.setMyLocationEnabled(true);
}
else
{
// Show rationale and request permission.
}
}
}


In AndroidManifest.xml I have:

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


Thanks in advance.

Answer

Add to your code :

import android.Manifest;