近接通知を処理するアプリを開発中です。近接アラートを追加することはできますが、これらの近接アラートを削除することはできません。私は電話と仮想デバイスの両方で自分のコードを試しましたが、私はそれらを削除することができませんでした。ここで Android近接通知を削除する
は私のコードです:データベースと近接アラートに保存された場所が
saveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String title = titleText.getText().toString();
if(title.matches("")){
Toast.makeText(CurrentLocationActivity.this,"Please provide a Title",Toast.LENGTH_SHORT).show();
}
else{
saveLocation(saveProximityAlertPoint(title));
setResult(RESULT_OK);
Toast.makeText(CurrentLocationActivity.this,"Location Saved",Toast.LENGTH_SHORT).show();
}
}
});
private void saveLocation(int unique_location_id) {
if (location == null) {
Toast.makeText(this, "No last known location",Toast.LENGTH_LONG).show();
return ;
}
else{
String title = titleText.getText().toString();
String type = typeSpinner.getSelectedItem().toString();
range = (int) (radius + POINT_RADIUS);
int unique_id = unique_location_id;
Double latitude = location.getLatitude();
Double longitude = location.getLongitude();
location_id = mDbHelper.createLocation(title, type, range, unique_id, latitude, longitude);
titleText.setText("");
radiusBar.setProgress(0);
}
}
private int saveProximityAlertPoint(String title) {
if (location == null) {
Toast.makeText(this, "No last known location.",Toast.LENGTH_LONG).show();
return 0;
}
else{
Double latitudeProxAlert = location.getLatitude();
Double longitudeProxAlert = location.getLongitude();
int unique_location_id = addProximityAlert(latitudeProxAlert, longitudeProxAlert, title);
return unique_location_id;
}
}
private int addProximityAlert(double latitude, double longitude, String title) {
Intent intent = new Intent(PROX_ALERT_INTENT);
intent.putExtra(LOCAION_TITLE, title);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, ++pending_intent_unique_id , intent, 0);
locationManager.addProximityAlert(latitude, longitude, range, PROX_ALERT_EXPIRATION, proximityIntent);
IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
registerReceiver(new ProximityIntentReceiver(), filter);
Toast.makeText(this, "Proximity has been added for " + title + " with unique_id " + pending_intent_unique_id,
Toast.LENGTH_LONG).show();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("UNIQUEID", pending_intent_unique_id);
editor.commit();
return pending_intent_unique_id;
}
と私は近接イッツ
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_delete:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
Cursor proxRemoveCursor = mDbHelper.fetchLocation(info.id);
removeProximityAlert(proxRemoveCursor.getInt(proxRemoveCursor.getColumnIndexOrThrow(DBAdapter.KEY_UNIQUE_LOCATION_ID)));
mDbHelper.deleteLocation(info.id);
proxRemoveCursor.close();
return true;
}
private void removeProximityAlert(int unique_id) {
String context = Context.LOCATION_SERVICE;
LocationManager locationManager = (LocationManager) getSystemService(context);
Intent anIntent = new Intent(REMOVE_PROXIMITY);
PendingIntent operation =
PendingIntent.getBroadcast(getApplicationContext(), unique_id , anIntent, 0);
locationManager.removeProximityAlert(operation);
}
}
警告削除しようとした他の活動を追加した活動ちょっと長いコードですが、それは私の質問を正しく行うための最短の方法です。ヘルプのThnx。
最終的なコードを表示できるので、問題解決の方法を確認できますか? – deucalion0
インテントanIntent =新しいインテント(REMOVE_PROXIMITY);意図インテント=新しいインテント(PROX_ALERT_INTENT);私の最終的なコードはそこにあります。問題はです。 REMOVE_PROXIMITYとPROX_ALERT_INTENTは一致する必要があります。最初に試したとき、彼らは違っていた。それらが同じであれば、近接警告を取り除くことができます。 – mkeremkeskin
私に返信してくれてうれしく思います。 – deucalion0