1
안녕하세요.여러 지역 알림 android
내가 내 응용 프로그램에서 여러 지역 알림을하려는, 그래서 내 활동에
을 가지고,이 17시 20분, 17시 21분, 17시 22분에 알람을 설정해야합니다 방법,하지만 난 하나가 통지 17시 22 분.
public void multiplyAlerts(){
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, LocalNotification.class);
for(int i = 0; i < 3; i++){
Calendar t_calendar = Calendar.getInstance();
t_calendar.set(Calendar.MONTH, Calendar.DECEMBER);
t_calendar.set(Calendar.YEAR, 2013);
t_calendar.set(Calendar.DAY_OF_MONTH, 12);
t_calendar.set(Calendar.HOUR_OF_DAY, 17);
t_calendar.set(Calendar.MINUTE, 20 + i);
t_calendar.set(Calendar.SECOND, 23);
t_calendar.set(Calendar.AM_PM, Calendar.PM);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
alarmManager.set(AlarmManager.RTC_WAKEUP, t_calendar.getTimeInMillis(),pendingIntent);
System.out.println("Calling Alarm " + i);
}}
지역 알림 클래스는
public class LocalNotification extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Remsmed";
CharSequence message = "Принимать что-то";
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
Notification notif = new Notification(R.drawable.launcher,"Notification text", System.currentTimeMillis());
notif.setLatestEventInfo(context, from, message, pendingIntent);
notif.flags = Notification.FLAG_AUTO_CANCEL;
nm.notify((int)System.currentTimeMillis(),notif);
System.out.println("id = " + System.currentTimeMillis());
}}
그리고
<receiver android:name="ru.fors.remsmed.utils.LocalNotification"></receiver>
당신이 답을 주셔서 감사 명단이 문자열을 추가!
(INT)에 System.currentTimeMillis()는 ID와 괜찮아? – Valeriy
예, 사용 가능합니다. –
한 번에 하나의 알림 만 설정하여이 문제를 방지 할 수도 있습니다. 17:20 알람이 울리면 17:21 알람 등을 설정하십시오. 한 번에 하나만 활성화되므로 알람을 취소하는 것이 더 쉬워집니다. – Kuffs