我有删除邻近警报的问题,而对于测试我尝试添加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进行了测试,并且没有删除接近度,并且广播仍然接收事件。 我错了什么?
答案 0 :(得分:1)
在addProximityAlert()
方法中,您传递-1作为到期值,这意味着您的地理位置不会过期(Geofence.NEVER_EXPIRE
)。这就是为什么geofrence没有删除。更改此标记并尝试试。