Set notification at specific time android

风流意气都作罢 提交于 2019-11-29 09:39:51

问题


I realize this question has been asked before, but I'm at my wit's end with this one.

I have an alarm manager to set up a notification:

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);

}

... And then I have the notification itself that is a service:

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;
    }

}

.... I included the toast to make sure that I was actually going to this method. The toast comes up, but the notification does not. What am I doing wrong here? Is it something in the manifest file I need to change?


回答1:


notifications do not work without an icon (or is it title?).

I'm sure I faced the same problem before that there's one of the elements of the notification that if you omit it, the notification won't show.



来源:https://stackoverflow.com/questions/14241439/set-notification-at-specific-time-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!