我正在處理藥物和約會的警報......當我設置鬧鐘時,我會在鬧鐘響起後放置額外的數據以便使用它們。 這裏是一些代碼來設置一個報警藥在我的公共類AlarmUtil:爲什麼獲取額外的數據總是返回null?
private static void setLimitedDurationAlarms(Context ctxt, MedicineClass med)
{
long ONE_DAY = 86400000;
AlarmManager mgr = (AlarmManager) ctxt.getSystemService(Context.ALARM_SERVICE);
// set up the first alarm
Calendar firstDoseTime = med.getFirstDoseTime();
// get firstDoseDate
Calendar firstDoseToday = med.getStartDate();
// set the time for the first dose for today.
firstDoseToday.set(Calendar.HOUR_OF_DAY, firstDoseTime.get(Calendar.HOUR_OF_DAY));
firstDoseToday.set(Calendar.MINUTE, firstDoseTime.get(Calendar.MINUTE));
Intent i = new Intent(ctxt, OnAlarmReceiver.class);
i.putExtra("MEDICINE", med.getName());
i.putExtra("LAST_ALARM", "FALSE");
PendingIntent pi = PendingIntent.getBroadcast(ctxt, getUniqueID(), i, 0);
mgr.set(AlarmManager.RTC_WAKEUP, firstDoseToday.getTimeInMillis(), pi);
……….
……
當接到報警...。我需要獲取警報的額外數據,以瞭解它是否用於醫療或預約..還可以使用每種醫療或應用程序的具體數據來獲取對象並通過通知顯示其信息。下一個代碼..
public class OnAlarmReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context ctxt, Intent intent)
{
Log.d("Alarm", "Alarm OFF! BEEP BEEP BEEP!");
Bundle data = intent.getExtras();
String medicine = (String) data.getCharSequence("MEDICNIE");
String appointment = (String) data.getCharSequence("APPOINTMENT");
String AppAction = (String) data.getCharSequence("APP_ACTION");
if (medicine == null)
// this alarm is not for medicine = for App
// use "appointment" values to get the appointment object from appointment list
else
// this is medicine alarm..
// use "medicine" value to get the medicine object form medicines list
…….
問題是我從意圖額外數據中獲得的所有數據總是返回null!
請如果有人知道這個問題,我希望以最簡單的方式回答我,因爲我很新的android ..
等待幫助。
其中ar您是否在捆綁中設置值? – waqaslam 2012-04-20 11:55:16