Search in sources :

Example 51 with LocationManager

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();
    }
}
Also used : LocationManager(android.location.LocationManager)

Example 52 with LocationManager

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;
}
Also used : LocationManager(android.location.LocationManager) Status(com.google.android.gms.common.api.Status) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest)

Example 53 with LocationManager

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;
}
Also used : LocationManager(android.location.LocationManager) Criteria(android.location.Criteria) Location(android.location.Location)

Example 54 with LocationManager

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));
        }
    }
}
Also used : LocationManager(android.location.LocationManager)

Example 55 with LocationManager

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;
}
Also used : LocationManager(android.location.LocationManager) ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint)

Aggregations

LocationManager (android.location.LocationManager)151 Location (android.location.Location)51 Bundle (android.os.Bundle)33 LocationListener (android.location.LocationListener)29 Criteria (android.location.Criteria)21 Intent (android.content.Intent)20 BluetoothAdapter (android.bluetooth.BluetoothAdapter)15 View (android.view.View)10 SuppressLint (android.annotation.SuppressLint)9 IOException (java.io.IOException)9 ConnectivityManager (android.net.ConnectivityManager)7 WifiManager (android.net.wifi.WifiManager)7 TextView (android.widget.TextView)7 DialogInterface (android.content.DialogInterface)6 IntentFilter (android.content.IntentFilter)6 SharedPreferences (android.content.SharedPreferences)6 PendingIntent (android.app.PendingIntent)5 NetworkInfo (android.net.NetworkInfo)5 TelephonyManager (android.telephony.TelephonyManager)5 TrackerDataHelper (com.android.locationtracker.data.TrackerDataHelper)5