2012-05-01 71 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设置通知。