-2

我在删除接近警报时遇到问题,为了测试,我尝试添加 ProximityAlert 并在之后立即将其删除。我有这个功能:

public void addproximity(View v) {
    SharedPreferences sharedPref = getSharedPreferences("proximityService", Context.MODE_PRIVATE);

    int unique_id = sharedPref.getInt("PENDING_ID", 0);
    unique_id = unique_id+1;

    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putInt("PENDING_ID", unique_id);
    editor.commit();
    Intent intentNew = new Intent(PROX_ALERT_INTENT);

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    double latitude = 43.9297615;
    double longitude = 10.2035046;
    PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), unique_id, intentNew, 0);
    lm.addProximityAlert(latitude, longitude, 200, -1, pi);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
    mHandleMessageReceiver = new ProximityAlertReceiver();
    registerReceiver(mHandleMessageReceiver, filter);


    lm.removeProximityAlert(pi);

}

但我用假gps测试,没有删除接近度,广播仍然接收事件。我错了什么?

4

1 回答 1

1

addProximityAlert()方法中,您将 -1 作为到期值传递,这意味着您的 geofrence 不会过期(Geofence.NEVER_EXPIRE)。这就是 geofrence 没有删除的原因。更改此标志并重试。

于 2016-09-06T10:59:30.007 回答