我正在通过警报管理器重复设置多个警报,它们在设置的那天工作正常,但根本不重复。我已经更新了我的代码,但我等不及要检查代码是否正常工作,所以我尝试了 adb shell dumpsys alarm 命令,但我不知道如何正确读取输出以及如何提取时间正在设置的警报。我已经按照一些链接来了解输出,但没有指定如何检查设置警报的确切时间。这是我的输出
我设置闹钟的主要代码
final int _id = (int) System.currentTimeMillis();
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,AllTime[i],AlarmManager.INTERVAL_DAY,
// PendingIntent.getBroadcast(this, _id, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT));
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP,AllTime[i],AlarmManager.INTERVAL_DAY,
PendingIntent.getBroadcast(this, _id, alertIntent, PendingIntent.FLAG_UPDATE_CURRENT));
这是广播接收器
public void onReceive(Context context, Intent intent) {
String[] myStrings = intent.getStringArrayExtra("strings");
Log.i("okk", "cathing intent values through break" + Arrays.toString(myStrings));
createNotification(context, "Time is here baby", "this is the notification text", "Alert");
Log.i("okk", "cathing intent values through break" + Arrays.toString(myStrings));
}
public void createNotification(Context context, String msg, String msgText, String msgAlert) {
final int _id = (int) System.currentTimeMillis(); // unique request code
// will open mainActivity on notification click, can change it
// PendingIntent notificationIntent = PendingIntent.getActivity(context, _id, new Intent(context, MainActivity.class), 0); // changed from 0 to _id
PendingIntent notificationIntent = PendingIntent.getActivity(context,0, new Intent(context,MainActivity.class),0);
NotificationCompat.Builder mbuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.cast_ic_notification_play)
.setContentTitle(msg)
.setTicker(msgAlert)
.setContentText(msgText);
// now intent we want to fire when noti is clicked
mbuilder.setContentIntent(notificationIntent);
// how person is notified
mbuilder.setDefaults(NotificationCompat.DEFAULT_SOUND);
mbuilder.setAutoCancel(true); // noti dismisble when user swipe it away
NotificationManager notificationManager = (NotificationManager)
context.getSystemService((Context.NOTIFICATION_SERVICE));
// Log.i("okk", "NOTIFIED " + intent.getExtras());
notificationManager.notify(1, mbuilder.build()); // changes from 1 to _id
}