ProximityAlert永远不会开火

时间:2011-02-23 04:42:33

标签: android

我的接近警报一直让我感到沮丧几分钟而且从未接触到接收器。

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 String key = LocationManager.KEY_PROXIMITY_ENTERING; Boolean entering = iIntent.getBooleanExtra(key,false); Log.d(Global.TAG,"-->!!!!! Proximity onReceive:"+entering+"\n"); }

给它一个旋转: 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;
}

}

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;
}

任何帮助都会像往常一样受到高度赞赏!

1 个答案:

答案 0 :(得分:0)

我刚制作了自己的版本,通过坐标列表并决定天气或不警报。随着时间的推移可能会增加CPU密集度,但至少它可以工作。