I tried to make an application that is using location. When I want location update an error appears and says "Call requires permission which may be rejected by user: code should explicitly check to see if permission is available (with checkPermission) or explicitly handle a potential SecurityException"
That's what I tried to put in my code
if (ContextCompat.checkSelfPermission( this,android.Manifest.permission.ACCESS_COARSE_LOCATION ) != PackageManager.PERMISSION_GRANTED )
{
ActivityCompat.requestPermissions(
this,
new String [] { android.Manifest.permission.ACCESS_COARSE_LOCATION },
LocationService.MY_PERMISSION_ACCESS_COARSE_LOCATION
);
}
But after I put that I got an error on LocationService which says "Cannot resolve symbol LocationService".
Here is my code
public void onCreate() {
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
contentIntent = PendingIntent.getActivity(
this, 0, notificationIntent, 0);
//updateNotification(false);
mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
mLocationManager.addGpsStatusListener(this);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 0, this);
}