我之前已经意识到这个问题已经被问过了,但是我已经结束了这个问题。
我有一个警报管理员来设置通知:
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;
}
}
....我包括吐司,以确保我实际上采用这种方法。吐司出现了,但通知没有。我在这做错了什么?是否需要更改清单文件中的内容?
答案 0 :(得分:11)
通知在没有图标(或标题?)的情况下无效。
我确信在此之前我遇到了同样的问题,通知的一个要素是,如果省略,通知将不会显示。