I tried setting up the gps permission for an andriod app using the below code in manifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
But when I execute I am not able to get the gps coordinates. I am getting "need permission" toast message. Need help. Here is my code snippet.
LocationManager locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new MyLocationListener();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast toast = Toast.makeText(getApplicationContext(), "no permission", Toast.LENGTH_LONG);
toast.show();
return;
}
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 5000, 10, locationListener);