2011-04-12 63 views
2

电话方法:通知的是Android立即设置

initNotificatie(endDate.getTime()); 
      Log.d("temp", "end: " + endDate.toGMTString()); // end: 13 Apr 2011 12:45:00 GMT 

的方法:

public void initNotificatie(long when)  { 
     String ns = Context.NOTIFICATION_SERVICE; 
     NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); 


     int icon = R.drawable.herinnering_button_dropdown; 
     String contentTitleString = getString(R.string.notification_title); 
     String contentTekstString = getString(R.string.notification_tekst); 
     CharSequence tickerText = "NotificationTekst"; 

     Notification notification = new Notification(icon, tickerText, when); 


     Context context = getApplicationContext(); 
     CharSequence contentTitle = contentTitleString; 
     CharSequence contentText = contentTekstString; 
     Intent notificationIntent = new Intent(this, MapDashboardActivity.class); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
    notification.defaults |= Notification.DEFAULT_SOUND; 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 
     final int HELLO_ID = 1; 
     mNotificationManager.notify(HELLO_ID, notification); 
} 

怎么会同时通知设置为明天该通知立即设置?这是因为我使用的通知构造函数已被弃用?我只能使用那个,因为我在4级编程。

+0

查看buzzbox sdk以轻松安排活动并创建通知。您可以为循环事件使用cron字符串。 http://hub.buzzbox.com – robsf 2011-04-12 16:44:05

回答

2

when参数指的是在时间字段中显示的时间。现在不是通知应该显示的时间。为了做到这一点,使用AlarmManager。