Java Code Examples for android.location.GpsStatus#Listener

The following examples show how to use android.location.GpsStatus#Listener . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GPSListenersMaker.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
public GpsStatus.Listener getGpsStatusListener() {
    return mStatusListener;
}
 
Example 2
Source File: GPSController.java    From cordova-plugin-advanced-geolocation with Apache License 2.0 4 votes vote down vote up
private static InitStatus setGPSStatusListener(){

        // IMPORTANT: The GpsStatus.Listener Interface is deprecated at API 24.
        // Reference: https://developer.android.com/reference/android/location/package-summary.html
        _gpsStatusListener = new GpsStatus.Listener() {

            @Override
            public void onGpsStatusChanged(int event) {
                Log.d(TAG, "GPS status changed.");

                // Ignore if GPS_EVENT_STARTED or GPS_EVENT_STOPPED
                if(!Thread.currentThread().isInterrupted() &&
                        (event == GpsStatus.GPS_EVENT_FIRST_FIX ||
                                event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) &&
                                        _locationManager != null){
                    sendCallback(PluginResult.Status.OK,
                            JSONHelper.satelliteDataJSON(_locationManager.getGpsStatus(null)));
                }
            }
        };

        final InitStatus status = new InitStatus();

        final Boolean gpsProviderEnabled = _locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        if(gpsProviderEnabled){
            try{
                _locationManager.addGpsStatusListener(_gpsStatusListener);
            }
            // if the ACCESS_FINE_LOCATION permission is not present
            catch(SecurityException exc){
                status.success = false;
                status.exception = exc.getMessage();
            }
        }
        else {
            //GPS not enabled
            status.success = false;
            status.error = ErrorMessages.GPS_UNAVAILABLE();
        }

        return status;
    }