开发者

ProximityAlert never fires

开发者 https://www.devze.com 2023-02-13 08:12 出处:网络
My proximity alert h开发者_如何学JAVAas been frustrating me for several minutes now and never gets to the receiver.

My proximity alert h开发者_如何学JAVAas been frustrating me for several minutes now and never gets to the receiver.

ProximityIntentReceiver.java

public class ProximityIntentReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context iContext, Intent iIntent) {

    String key = LocationManager.KEY_PROXIMITY_ENTERING;
    Boolean entering = iIntent.getBooleanExtra(key,false);

    Log.d(Global.TAG,"-->!!!!! Proximity onReceive:"+entering+"\n");
    }

}

Proximity.java

public class Proximity {
    public static String PROXIMITY_ALERT = "com.atClass.ProximityIntentReceiver";

public ProximityIntentReceiver setProximityAlert(double iLat, double iLng) {
    ProximityIntentReceiver lProximityIntentReceiver;

    Log.d(Global.TAG,"-->ProximityAlert set:" + iLat + "," + iLng);
    String locService = Context.LOCATION_SERVICE;
    LocationManager locationManager;
    locationManager = (LocationManager)Global.gActivity.getSystemService(locService);

    float radius = 1000f; //meters
    long expiration = -1; //never expire

    Intent intent = new Intent(PROXIMITY_ALERT);
    PendingIntent proximityIntent = PendingIntent.getBroadcast(Global.gContext,-1,intent,0);
    locationManager.addProximityAlert(iLat, iLng, radius, expiration, proximityIntent);

    IntentFilter filter = new IntentFilter(PROXIMITY_ALERT);
    lProximityIntentReceiver = new ProximityIntentReceiver();
    Global.gContext.registerReceiver(lProximityIntentReceiver,filter);
    return lProximityIntentReceiver;
}

}

Give it a whirl:

        ProximityTools.setupProximityList();
        ProximityTools.clearProximityLocations();

    Proximity lProximityAlert = new Proximity();
    lProximityAlert.setProximityAlert(43.647995,-79.4953733);

Any help is greatly appreciated as usual!


I just made my own version that goes through the list of coordinates and decides weather or not to alert. Probably more CPU intensive over time, but at least it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消