Commit ed6e7fa0 authored by Eddy Ernesto del Valle Pino's avatar Eddy Ernesto del Valle Pino Committed by Jason Simmons

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

parent e20ec2be
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment