Example usage for android.location LocationProvider getName

List of usage examples for android.location LocationProvider getName

Introduction

In this page you can find the example usage for android.location LocationProvider getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of this provider.

Usage

From source file:com.prey.services.LocationService.java

@Override
public void onCreate() {
    PreyLogger.d("LocationService is going to be started...");

    androidLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            || ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) {

        LocationProvider gpsLocationProvider = androidLocationManager.getProvider(LocationManager.GPS_PROVIDER);
        LocationProvider networkProvider = androidLocationManager.getProvider(LocationManager.NETWORK_PROVIDER);
        if (gpsLocationProvider != null
                && androidLocationManager.isProviderEnabled(gpsLocationProvider.getName())) {
            androidLocationManager.requestLocationUpdates(gpsLocationProvider.getName(),
                    PreyConfig.UPDATE_INTERVAL, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE,
                    gpsLocationListener);
            PreyLogger.d("GPS Location provider has been started.");
        }/*from   www  . jav a  2  s .c o  m*/
        if (networkProvider != null && androidLocationManager.isProviderEnabled(networkProvider.getName())) {
            androidLocationManager.requestLocationUpdates(networkProvider.getName(),
                    PreyConfig.UPDATE_INTERVAL / 4, PreyConfig.LOCATION_PROVIDERS_MIN_REFRESH_DISTANCE,
                    networkLocationListener);
            PreyLogger.d("NETWORK Location provider has been started.");
        }
    } else {
        PreyLogger.i("___________ask for permission LocationService ACCESS_FINE_LOCATION");
    }

    PreyLogger.d("LocationService has been started...");
}