2011-02-03 55 views
2

我正试图在笔记/待办事项应用中获得提醒/警报服务。我可以为特定项目和警报触发器设置提醒并成功显示通知。以初始值启动服务

我的问题是我的Service怎么知道哪个笔记/待办事项设置了特定的提醒。我希望用户能够点击状态栏中的通知并获得触发它的项目。但我无法将这些信息传递给Service,因为他们不接受PendingIntent中的Bundles

我当前设置的报警有以下:

private void createAlarm() { 
    Intent i = new Intent(this, AlarmService.class); 
    PendingIntent sender = PendingIntent.getService(this, 0, i, 0); 
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); 
    am.set(AlarmManager.RTC_WAKEUP, mReminderCal.getTimeInMillis(), sender); 
} 

我只是需要一种方法来一起在我的数据库项目的_id派,所以我的服务可以用相同的_id启动项时通知被点击。

我希望我的问题不是太混乱。

谢谢!

回答

1

为什么不把所有需求都放到Intent数据中?事情是这样的:

final Intent intent = new Intent(context, UpdatesActivity.class); 
    intent.putExtra(ID, "foo"); 
    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 

然后在接收端你做

String id = getIntent().getStringExtra(ID); 
+0

但是这会起作用了`Service`?注意我正在使用`PendingIntent.getService()`。当我尝试在我的服务中从`onCreate()`调用`getIntent()`时,它的undefined :( – 2011-02-03 16:10:31