Ask if the app has location access before asking for location. (#5659)

This commit is contained in:
Eddy Ernesto del Valle Pino
2016-08-31 18:54:15 +02:00
committed by Jason Simmons
parent e20ec2becb
commit ed6e7fa06f

View File

@@ -8,6 +8,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
@@ -142,9 +143,12 @@ public class ExampleActivity extends Activity {
return null;
}
LocationManager locationManager =
(LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(locationProvider);
String permission = "android.permission.ACCESS_FINE_LOCATION";
Location location = null;
if (checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
location = locationManager.getLastKnownLocation(locationProvider);
}
JSONObject reply = new JSONObject();
try {