Zdaję sobie sprawę, że to pytanie zostało zadane wcześniej, ale jestem na tym dowcipny koniec tego.Ustaw powiadomienie o konkretnej godzinie android
mam menedżera alarmu, aby skonfigurować powiadomienia:
public void to_reminder(View view)
{
Intent intent=new Intent(this,Notification_morning.class);
AlarmManager manager=(AlarmManager)getSystemService(Activity.ALARM_SERVICE);
PendingIntent pendingIntent=PendingIntent.getService(this,
0,intent, 0);
Calendar cal=Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, timepicker.getCurrentHour());
cal.set(Calendar.MINUTE,timepicker.getCurrentMinute());
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
manager.setRepeating(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),24*60*60*1000,pendingIntent);
}
... A potem muszę sam powiadomienie, że jest to usługa:
public class Notification_morning extends Service {
@Override
public void onCreate()
{
Toast.makeText(this, "MyAlarmService.onCreate()", Toast.LENGTH_LONG).show();
Intent resultIntent=new Intent(this, Calendar_start.class);
PendingIntent pIntent=PendingIntent.getActivity(this,0,resultIntent,0);
Notification noti_builder= new Notification.Builder(this)
.setContentTitle("Don't forget to plan your activitites for the day! ")
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //what does this do!?
noti_builder.flags |=Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(1,noti_builder);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
. ... Wziąłem toast, aby upewnić się, że faktycznie zamierzam zastosować tę metodę. Toast pojawia się, ale powiadomienie nie. Co ja tu robię źle? Czy jest to coś w pliku manifestu, który muszę zmienić?
WOW. Tak, to była ikona. Przynajmniej dowiedziałem się o wielu innych rzeczach, przeglądając całą dokumentację :). Przyjmie tę odpowiedź, gdy tylko minie czas oczekiwania. – sam