问题描述
#此方法用于通过具有不同ID的警报管理器触发待定意图#i只想在30秒后为每个ID创建待定意图,我想取消触发器ID#
int公告ID = 1、2、3、4、5、6、7(该ID将通过未经过硬编码的api动态获取,因此可以为1到100); `
public void setok(Context context,int okId) {
triggerAlarm(context,okId);
}
private void triggerAlarm(Context context,int bulletinid) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (alarmManager != null) {
Intent intent = new Intent(context,BulletinReceiver.class);
intent.putExtra("bulletinid",bulletinid);
PendingIntent pendingIntent = PendingIntent.getbroadcast(context,bulletinid,intent,PendingIntent.FLAG_UPDATE_CURRENT);
//set time to next 30 sec
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.SECOND,calendar.get(Calendar.SECOND) + 30);
alarmManager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),pendingIntent);
LogUtils.d(TAG,"triggerAlarm: ");
}
}
BulletinReceiver:
public class BulletinReceiver extends broadcastReceiver {
private static final String TAG = "BulletinReceiver";
int bulletiniD;
@Override
public void onReceive(Context context,Intent intent) {
LogUtils.d(TAG,"onReceive: ");
bulletiniD = intent.getIntExtra("bulletinid",0);
Log.d("Sathish","onreciver: bulletinid: " + bulletiniD);
ArrayList<Integer> okBulletinidList = SharedPreferenceUtils.getInstance(context).geOkBulletinidList();
if(okBulletinidList.size()>0){
okBulletinidList.remove((Integer) bulletiniD);
}
SharedPreferenceUtils.getInstance(context).setokBulletinidList(okBulletinidList);
BulletinMessageUtils.getInstance().setBulletinTimerFlag(context,bulletiniD);
Log.d("Sathish","onreciver canceld: bulletinid: " + SharedPreferenceUtils.getInstance(context).geOkBulletinidList().toString());
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)