2013-01-09 70 views
10

我意識到這個問題之前已經被問過了,但我在這個智能機器人的末端。在特定時間設置通知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; 
    } 

}

。 ......我包括敬酒,以確保我實際上正在採用這種方法。吐司來了,但通知不。我在這裏做錯了什麼?是否需要更改清單文件中的某些內容?

回答

11

如果沒有圖標(或者是標題?),通知不起作用。

我確定我在面對同樣的問題之前,有一個通知的元素,如果你忽略它,通知將不會顯示。

+1

WOW。是的,它是圖標。至少我在瞭解所有文檔的同時瞭解了很多其他的東西:)。一旦等待時間結束,將接受這個答案。 – sam