gpt4 book ai didi

android - 为什么获取额外数据总是返回null?

转载 作者:行者123 更新时间:2023-11-29 13:59:23 24 4
gpt4 key购买 nike

我正在研究药物和约会的警报……当我设置警报时,我会放置额外的数据以便稍后在警报响起时使用它们……。这是在我的公共(public)类 AlarmUtil 中设置药物警报的一些代码:

 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
…….

问题是我从 Intent 额外数据中获得的所有数据总是返回 null !

请如果有人知道这个问题,我希望以最简单的方式回答我,因为我是 android 的新手..
等待帮助。

最佳答案

检查 Medicine 的拼写

设置时:

i.putExtra("MEDICINE", med.getName());

阅读时:

data.getCharSequence("MEDICNIE");

其中“MEDICNIE”与“MEDICINE”不同

关于android - 为什么获取额外数据总是返回null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10245701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com