我有刪除接近警報的問題,並且對於測試,我嘗試添加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測試,接近不刪除,廣播仍然收到事件。 我錯了什麼?
但-1爲什麼?你能解釋我嗎? – LorenzoBerti