将额外的 Intent 传递给 Android 广播接收器
我创建了一个 AlarmReceiver 类,用作警报的广播接收器。问题是我需要从将警报设置为广播接收器类的类发送一些值。
setAlarmManager.java
Intent i = new Intent(mContext, AlarmReceiver.class);
i.putExtra(KEY_ROWID, (long)taskId);
PendingIntent pi = PendingIntent.getBroadcast(mContext,taskId_int,i,PendingIntent.FLAG_ONE_SHOT);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);
我需要从alarmreceiver类中的intent获取KEY_ROWID。我怎样才能做到这一点? AlarmReceiver 类如下所示。
public class AlarmReceiver extends BroadcastReceiver {
public static final String ALARM_ALERT_ACTION ="com.android.alarmclock.ALARM_ALERT";
public static final String ALARM_INTENT_EXTRA = "intent.extra.alarm";
@Override
public void onReceive(Context context, Intent intent) {
//Here I need the values from intent using bundle or anything...
}
}
I have created a AlarmReceiver class which is used as broadcast receiver for alarm. The issue is that I need to send some values from the class which is setting the alarm to the broadcast receiver class.
setAlarmManager.java
Intent i = new Intent(mContext, AlarmReceiver.class);
i.putExtra(KEY_ROWID, (long)taskId);
PendingIntent pi = PendingIntent.getBroadcast(mContext,taskId_int,i,PendingIntent.FLAG_ONE_SHOT);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);
I need to get the KEY_ROWID from intent in alarmreceiver class. How can I do that? The AlarmReceiver class is shown below.
public class AlarmReceiver extends BroadcastReceiver {
public static final String ALARM_ALERT_ACTION ="com.android.alarmclock.ALARM_ALERT";
public static final String ALARM_INTENT_EXTRA = "intent.extra.alarm";
@Override
public void onReceive(Context context, Intent intent) {
//Here I need the values from intent using bundle or anything...
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用:
You can use :