我创建了一个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...
}
}