5

With HERE Android SDK Premium, when using NavigationManager#simulate() method, if I add a NavigationManager.GpsSignalListener, the listener callbacks are not called even when I turn on/off my GPS while running on an emulator.

How do I receive GPS signal events while running NavigationManager in simulation mode?

curioustechizen
  • 10,572
  • 10
  • 61
  • 110

1 Answers1

3

Listening to the turning on/off of the GPS can be done via LocationManager for the status (enabled/disabled) of the GPS/Network provider. This is different from the HERE Android SDK's GpsSignalListener which is for GPS signal lost (e.g when in a tunnel) and restore (i.e when you exit the tunnel) events.

So for listening to the on/off of the GPS of your phone/Android emulator, you need to subscribe to the broadcast messages from the Android system and check for LocationManager.PROVIDERS_CHANGED_ACTION. See sample code snippet in an Activity:

@Override
protected void onResume() {
    super.onResume();
    IntentFilter iFilter = new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION);
    filter.addAction(Intent.ACTION_PROVIDER_CHANGED);
    this.registerReceiver(gpsOnOffReceiver, iFilter);
}

private BroadcastReceiver gpsOnOffReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        if (LocationManager.PROVIDERS_CHANGED_ACTION.equals(intent.getAction())) {

            LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
            boolean gpsOn = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
            boolean networkOn = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

            if (gpsOn || networkOn) {
                // GPS is ON
                Log.d("GPS", "GPS turned ON");
            } else {
                // GPS is OFF
                Log.d("GPS", "GPS turned OFF");
            }
        }
    }
};
  • Ah I see. The HERE SDK docs certainly don't make this obvious! There is no mention of what GpsSignalListener even means. – curioustechizen May 10 '19 at 06:57
  • Yes, a bit more explanation on the GpsSignalListener would help. We will take care of that. Thanks. –  May 10 '19 at 07:29
  • But this doesn't actually answer the question - Is there a way to trigger GpsSignalListener when I'm using NavigationManager.simulate()? – curioustechizen May 10 '19 at 08:12