GpsStatus.Listener is only registered if GPS is enabled

I have a widget that displays the current location of the user using the LocationManager. I save battery by disabling the local mailing list manager to update the location via the system mailing manager which indicates if the screen is on. To accompany the battery saving efforts, I am trying to implement a GpsStatus.Listener to tell me if gps is enabled or disabled so I can use it in my location manager. Everything works fine if I load the widget ONLY IF GPS is enabled. GpsStatus.Listener not triggered if widget is loaded when GPS is disabled. Obviously there is a workaround for imperefct (loading with gps), but I'm curious and ask why the listener doesn't work if gps is disabled at runtime. I am using os 4.0.3 and my manifest includes exact location. that.

public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds)
    // Get all ids
    thisWidget = new ComponentName(context, MyWidgetProvider.class);
    this.appWidgetManager = appWidgetManager;
    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);

    remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
    remoteViews.setTextViewText(, "running......");
    appWidgetManager.updateAppWidget(thisWidget, remoteViews);

    ServicesManager = new MyLocationManager(context);
    streetAddress = new CellAddress(context, ServicesManager);

    filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    context.getApplicationContext().registerReceiver(mReceiver, filter);

            new IntentFilter("sendUpdatedLocation"));

    if (!(ServicesManager.isInternet()))
        remoteViews.setTextViewText(, "Address not available" + "\n\n" +
                                    "Check data connection....");
        appWidgetManager.updateAppWidget(thisWidget, remoteViews);
        remoteViews.setTextViewText(, streetAddress.address$);
        appWidgetManager.updateAppWidget(thisWidget, remoteViews);

    Log.d(TAG, "onUpdate");

GpsStatus.Listener myGPSListener = new GpsStatus.Listener() 

    public void onGpsStatusChanged(int event) 
        if(event == GpsStatus.GPS_EVENT_STARTED)
        Log.d(TAG, "GPS Started");  
        } else if(event == GpsStatus.GPS_EVENT_STOPPED) {
        Log.d(TAG, "GPS Stopped");




source to share

All Articles