在特定时间设置通知Android
我知道这个问题以前曾被问过,但我已不知所措。
我有一个警报管理器来设置通知:
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);
}
…然后我得到了通知本身即服务:
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;
}
}
....我加入了吐司,以确保我确实要使用此方法。敬酒,但通知没有。我在这里做错了什么?我需要更改清单文件中的内容吗?
回答:
没有图标(或标题是?)的通知将不起作用。
我确信我遇到了同样的问题,因为如果您忽略了通知的内容之一,则通知将不会显示。
以上是 在特定时间设置通知Android 的全部内容, 来源链接: utcz.com/qa/407173.html