2012-05-01 65 views
0

我希望能夠每週通知用戶執行任務。我知道我需要做什麼,但不知道如何去做。我需要以某種方式將註釋掉的代碼(最後一行)傳遞給AlarmManager。使用AlarmManager啓動通知

 Context context = getApplicationContext(); 
     CharSequence contentTitle = notiType+" reminder for "+projName; 
     CharSequence contentText = "Take your photo now!"; 
     Intent notificationIntent = new Intent(getApplicationContext(), ProjectPreview.class); 
     notificationIntent.putExtra("projname", "asdsad"); 
     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
     notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 
     am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), contentIntent); 

     //mNotificationManager.notify(1, notification); 

有人能幫助我嗎?

回答

1

您可以告訴您的AlarmManager調用BroadcastReceiver(通過使用PendingIntent.getReceiver)。

在接收方onReceive()方法中,使用NotificationManager設置通知。