没有删除接近警报

时间:2015-11-06 10:01:49

标签: android gps proximity

我正在创建一个应用来添加和删除邻近警报。 接近警报工作正常。当我接近坐标时它会通知我。但是当我不想要它们时,我无法删除它们。以下是我用来添加和删除proximity alerts的代码。

当我停下来阅读它们时,警报的数量比前一次增加一个。

添加邻近警报

private void add_lert() {
    locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, this);
    String proximitys="com.realtech.proxtest";
    Intent i=new Intent(proximitys);
    pi = PendingIntent.getBroadcast(MainActivity.this, 11, i, PendingIntent.FLAG_CANCEL_CURRENT);
    locationManager.addProximityAlert(lat, lng, radius, -1, pi);
    IntentFilter filter=new IntentFilter(proximitys);
    registerReceiver(new ProxReceiver(),filter);
}

删除提醒

private void remove_alert() {
    LocationManager locationManager1=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    String proximitys="com.realtech.proxtest";
    Intent i=new Intent(proximitys);
    PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 11, i, PendingIntent.FLAG_CANCEL_CURRENT);
    locationManager1.removeProximityAlert(pi);
}

1 个答案:

答案 0 :(得分:0)

您是否尝试为PendingIntent使用全局变量,而是在每个块中声明一个新变量(添加/删除)。

此外,locationManager在两个块中具有不同的名称。尝试使用全局变量。