我正在通过这个向警报管理器发送一个请求代码
Intent broadcast_intent = new Intent(this, AlarmBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, rowId, broadcast_intent, PendingIntent.FLAG_UPDATE_CURRENT);我想知道,在broadcastreceiver中,我如何检索我用来设置pendingIntent的请求码(rowId)?
谢谢
发布于 2012-12-31 07:14:29
我也在找同样的东西。一种方法是在您的意图中将requestcode作为额外代码传递。
intent.putExtra("requestcode", rowId);然而,,如果应用程序被终止,就没有办法检索由Intent传递的数据。
因此,您需要将rowId作为URI传递,并使用意图过滤器。
发布于 2014-04-06 18:16:55
Intent broadcast_intent = new Intent(this, AlarmBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, rowId,
broadcast_intent,PendingIntent.FLAG_UPDATE_CURRENT
);最好是在getBroadcast() - broadcast_intent.putExtras("REQUESTCODE",rowId) ;中引用broadcast_intent时传递额外的参数,如下所示:
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, rowId,
broadcast_intent.putExtras("REQUESTCODE",rowId),
PendingIntent.FLAG_UPDATE_CURRENT);发布于 2016-04-05 00:44:59
创建pendingIntent时使用的requestCode不是用来传递给接收器的,而是让创建pendingIntent的应用程序能够管理多个pendingIntents的一种方式。
假设一个告警应用需要创建多个pendingIntents,然后需要取消或修改其中的一个。requestCode用于标识要取消/修改哪一个。
要传递数据,请如上所述使用putExtra。注您可能非常希望对requestCode和额外数据都使用RowId。
https://stackoverflow.com/questions/12506391
复制相似问题