
我已经设置了一些警报,例如:
public voID SetAlarm(Context context, int tag, long time){ AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, Alarm.class); i.putExtra("position", tag); PendingIntent pi = PendingIntent.getbroadcast(context, tag, i, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ time, pi); // Millisec * Second * Minute }现在由于某种原因,我想更新触发警报的意图.我有用于识别欲望警报的ID(标签).我怎样才能做到这一点 ?
解决方法:
如果您要做的只是更改Intent中的其他功能,则可以这样 *** 作:
Intent i = new Intent(context, Alarm.class);// Set new extras herei.putExtra("position", tag);// Update the PendingIntent with the new extrasPendingIntent pi = PendingIntent.getbroadcast(context, tag, i, PendingIntent.FLAG_UPDATE_CURRENT);否则,如果要更改Intent中的其他任何内容(例如动作,组件或数据),则应取消当前警报并创建一个新警报,如下所示:
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);Intent i = new Intent(context, Alarm.class);// Extras aren't used to find the PendingIntentPendingIntent pi = PendingIntent.getbroadcast(context, tag, i, PendingIntent.FLAG_NO_CREATE); // find the old PendingIntentif (pi != null) { // Now cancel the alarm that matches the old PendingIntent am.cancel(pi);}// Now create and schedule a new Alarmi = new Intent(context, Newalarm.class); // New component for alarmi.putExtra("position", tag); // Whatever new extraspi = PendingIntent.getbroadcast(context, tag, i, PendingIntent.FLAG_CANCEL_CURRENT);// Reschedule the alarmam.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ time, pi); // Millisec * Second * Minute 总结 以上是内存溢出为你收集整理的android-更改alarmmanager使用的pendingMetent的意图全部内容,希望文章能够帮你解决android-更改alarmmanager使用的pendingMetent的意图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)