在特定时间设置通知android [英] Set notification at specific time android
问题描述
我意识到以前有人问过这个问题,但我对这个问题不知所措.
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;
}
}
.... 我加入了 toast 以确保我真的要使用这种方法.吐司出现,但通知没有.我在这里做错了什么?我需要更改清单文件中的内容吗?
.... 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?
推荐答案
通知在没有图标(或者是标题?)的情况下不起作用.
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.
这篇关于在特定时间设置通知android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!