Set 2 proximity alerts with the same broadcast

I create a proximity alert this way

    private void setProximityAlert(float radius, double lat, double lng, String place)
{
    long expiration = -1;
    LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Intent intent = new Intent(TREASURE_PROXIMITY_ALERT);
    intent.putExtra("lat", lat);
    intent.putExtra("lng", lng);
    intent.putExtra("place", place);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), -1, intent, 0);   
    locManager.addProximityAlert(lat, lng, radius, expiration, pendingIntent);
}

and in my activity I registered the receiver in this way

    IntentFilter intentFilter = new IntentFilter(TREASURE_PROXIMITY_ALERT);
    registerReceiver(new ProximityIntentReceiver(), intentFilter);
    setProximityAlert(10, 45.150344, 9.999815, "POINT1");

and my broadcast receiver is correctly called. So now I want to add another proximity warning, is this possible? I want the same boadcast receiver to be triggered by two proximity alerts. I have done this:

    IntentFilter intentFilter1 = new IntentFilter(TREASURE_PROXIMITY_ALERT1);
    registerReceiver(new ProximityIntentReceiver(), intentFilter1);        
    setProximityAlert(200f, 45.143848, 10.039741, "POINT2");

but it does not work, nothing happens. I actually am now, and I was wondering if this is right. My intention is trigger signals 2 when the GPS gets the position of POINT1 and the other at position POINT2. Any hints are welcome.

+3
source share
1 answer

setAction, -, .

:

Intent intent = new Intent(this,PlacesProximityHandlerService.class);
intent.setAction("foo"+objPlace.getId());
intent.putExtra(Poi._ID, objPlace.getId());
intent.putExtra(Poi.LAT, objPlace.getLat());
intent.putExtra(Poi.LON, objPlace.getLon());
PendingIntent sender = PendingIntent.getService(this,0, intent, 0);
LocationUtils.addProximity(this, objPlace.getLat(),objPlace.getLon(), objPlace.getError(), -1,sender);

, .

ZONE1 . = true ZONE1. ZONE2, , , ZONE1. ZONE1, enter = false. , ZONE1, ZONE2, = true ZONE2.

, . Location Spoofer . . :

<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

, , , , , ZONE1, . Greeland , ZONE2, .

Bundle b = intent.getExtras();
Boolean entering = (Boolean) b.get(android.location.LocationManager.KEY_PROXIMITY_ENTERING);

100 POI, .

+6

Source: https://habr.com/ru/post/1755719/


All Articles