Java Code Examples for android.location.LocationManager#PROVIDERS_CHANGED_ACTION

The following examples show how to use android.location.LocationManager#PROVIDERS_CHANGED_ACTION . 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: GeoEnabledConsistencyReceiverTest.java    From mobile-messaging-sdk-android with Apache License 2.0 6 votes vote down vote up
@Override
public void setUp() throws Exception {
    super.setUp();

    providersChangedIntent = new Intent(LocationManager.PROVIDERS_CHANGED_ACTION);

    locationManagerMock = Mockito.mock(LocationManager.class);
    geoHelperMock = Mockito.mock(GeofencingHelper.class);
    geoEnabledConsistencyReceiverWithMock = new GeoEnabledConsistencyReceiver(geoHelperMock);
    geoHelperSpy = Mockito.spy(GeofencingHelper.class);
    geoEnabledConsistencyReceiverWithSpy = new GeoEnabledConsistencyReceiver(geoHelperSpy);

    AlarmManager alarmManagerMock = Mockito.mock(AlarmManager.class);
    //noinspection WrongConstant
    Mockito.when(contextMock.getSystemService(Mockito.eq(Context.ALARM_SERVICE))).thenReturn(alarmManagerMock);
}
 
Example 2
Source File: GeofenceReceiver.java    From android-sdk with MIT License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) { //TODO add wakelocks
    if (blocked()) return;
    String action = intent.getAction();
    if (action == null || action.isEmpty()) {
        Logger.log.geofenceError("Received intent without action",null);
        return;
    }
    switch (action) {
        case ACTION_GEOFENCE:
            handleGeofence(context, intent);
            break;
        case ACTION_LOCATION_UPDATE:
            handleLocationUpdate(context, intent);
            break;
        case LocationManager.PROVIDERS_CHANGED_ACTION:
            //Listening to this may cause trouble with some mock location apps that are spamming this action.
            handleProvidersChanged(context);
            break;
        default:
            Logger.log.geofenceError("Received intent with unknown action " + action, null);
            break;
    }
}
 
Example 3
Source File: GeofencingImpl.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
public void setGeoComponentsEnabledSettings(Context context, boolean componentsStateEnabled) {
    ComponentUtil.setState(context, componentsStateEnabled, GeofenceTransitionsReceiver.class);
    ComponentUtil.setState(context, componentsStateEnabled, GeofenceTransitionsIntentService.class);
    ComponentUtil.setState(context, componentsStateEnabled, GeofencingConsistencyReceiver.class);
    ComponentUtil.setState(context, componentsStateEnabled, GeofencingConsistencyIntentService.class);
    ComponentUtil.setState(context, componentsStateEnabled, BootReceiver.class);

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) {
        ComponentUtil.setState(context, componentsStateEnabled, GeoEnabledConsistencyReceiver.class);
        return;
    }

    // >= Android O
    if (componentsStateEnabled) {
        if (null != geoEnabledConsistencyReceiver) {
            return;
        }
        geoEnabledConsistencyReceiver = new GeoEnabledConsistencyReceiver();

        final IntentFilter intentFilter = new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION);
        context.registerReceiver(geoEnabledConsistencyReceiver, intentFilter);

    } else {
        if (null != geoEnabledConsistencyReceiver) {
            context.unregisterReceiver(geoEnabledConsistencyReceiver);
            geoEnabledConsistencyReceiver = null;
        }
    }
}