我正在調度任務,並根據日期和時間添加報警管理器,並計劃任務正在添加一個列表..當我添加任何任務,然後它也添加到sqlite數據庫並分配一個用於報警管理器的pendinng意圖的唯一ID。根據UniqueID取消報警管理器掛起的意圖android
現在,如果我想解僱警報,那麼如果我從列表中刪除該行,那麼我也想關閉該特定警報也..我能夠從數據庫中刪除行,但如何解除設置該行的警報?
我的代碼如下:
Button AddData=(Button)findViewById(R.id.senddata);
AddData.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);
Date= updatedate.getText().toString();
Time= updateTime.getText().toString();
Discripton= discription.getText().toString();
//---get current date and time---
Calendar calendar = Calendar.getInstance();
//---sets the time for the alarm to trigger---
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, mHour);
calendar.set(Calendar.MINUTE, mMinute);
calendar.set(Calendar.SECOND, 0);
Log.i("********####",year+" ,"+month+" , "+day+" , "+mHour+" , "+mMinute+"----"+ calendar.getTimeInMillis());
Intent intent = new Intent(AddEditExpense.this, TimeAlarm.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle b12 = new Bundle();
mStuffresults=Discripton;
b12.putString("serverresponse", mStuffresults);
intent.setAction("" + Math.random());
intent.putExtras(b12);
PendingIntent displayIntent = PendingIntent.getBroadcast(AddEditExpense.this,iUniqueId,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), displayIntent);
}
}
請在這裏也請參考:更新
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case DELETE_ID:
UniqueId=AddEditExpense.s;
Log.i("UniqueId",UniqueId);
Integer i = Integer.valueOf(UniqueId);
PendingIntent contentIntent = PendingIntent.getBroadcast(TaskReminder.this, i,
new Intent(),PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(contentIntent);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
mDbHelper.deleteNote(info.id);
fillData();
return true;
}
您還可以檢查我的答案[這裏](http://stackoverflow.com/questions/8877365/cancelling-a-single-alarm-when-you - 有多重報警/ 8877875#8877875) –