use of android.location.LocationManager in project SeniorProject by 5731075221-PM.
the class HospitalMapFragment method statusCheck.
public void statusCheck() {
System.out.println("statusCheck");
final LocationManager manager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
buildAlertMessageNoGps();
}
}
use of android.location.LocationManager in project iNaturalistAndroid by inaturalist.
the class INaturalistApp method isLocationEnabled.
/**
* Checks if place services are enabled
*/
public boolean isLocationEnabled(final OnLocationStatus locationCallback) {
// First, check if GPS is disabled
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean gpsEnabled = (lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
if (!gpsEnabled)
return false;
// Next, see if specifically the user has revoked place access to our app
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}
if (locationCallback != null) {
final LocationRequest locationRequest = new LocationRequest();
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(5000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
switch(status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// All place settings are satisfied. The client can initialize place
// requests here.
locationCallback.onLocationStatus(true);
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied
locationCallback.onLocationStatus(false);
break;
}
}
});
}
return gpsEnabled;
}
use of android.location.LocationManager in project iNaturalistAndroid by inaturalist.
the class INaturalistService method getLocationFromGPS.
private Location getLocationFromGPS() {
LocationManager locationManager = (LocationManager) mApp.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
Log.e(TAG, "getLocationFromGPS: " + location);
return location;
}
use of android.location.LocationManager in project HikingApp by wickhama.
the class Coordinates method onPermissionResult.
/**
*Created by Ryley Increment 1
* Modified by Caleigh
*
* Once permission has been granted, we can begin tracking coordinates
*/
@Override
public void onPermissionResult(boolean result) {
if (result) {
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
// Added to double-check that location is available ~Caleigh
if (locationManager != null) {
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
// begin tracking
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5, this);
// set the initial position
onLocationChanged(locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
}
}
}
use of android.location.LocationManager in project Osmand by osmandapp.
the class OsmAndLocationProvider method getFirstTimeRunDefaultLocation.
public net.osmand.Location getFirstTimeRunDefaultLocation() {
if (!isLocationPermissionAvailable(app)) {
return null;
}
LocationManager service = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);
List<String> ps = service.getProviders(true);
if (ps == null) {
return null;
}
List<String> providers = new ArrayList<String>(ps);
// note, passive provider is from API_LEVEL 8 but it is a constant, we can check for it.
// constant should not be changed in future
// LocationManager.PASSIVE_PROVIDER
int passiveFirst = providers.indexOf("passive");
// put passive provider to first place
if (passiveFirst > -1) {
providers.add(0, providers.remove(passiveFirst));
}
// find location
for (String provider : providers) {
net.osmand.Location location = convertLocation(service.getLastKnownLocation(provider), app);
if (location != null) {
return location;
}
}
return null;
}
Aggregations