我需要你的帮助!当我在 Intent 中添加额外内容然后使用该 Intent 创建 Pending Intent 时,它不起作用!我不参加 BroadCastReceiver 课程。
public class Recordatori_Visita extends Activity {
public void setAlarm(Calendar targetCal) {
Intent intent = new Intent (Recordatori_Visita.this, Receiver.class);
Long targetCal2 = targetCal.getTimeInMillis();
intent.putExtra("targetCal",targetCal2);
intent.putExtra("n",n);
PendingIntent pendingIntent = PendingIntent.getBroadcast(Recordatori_Visita.this, 1, intent, intent.FILL_IN_DATA);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(),pendingIntent);
}
}
.
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context k1, Intent k2) {
// TODO Auto-generated method stub
Bundle bolsaR = k2.getExtras();
Long extras = bolsaR.getLong("targetCalKey");
int n= bolsaR.getInt("n");
NotificationManager notificationManager = (NotificationManager) k1.getSystemService(Context.NOTIFICATION_SERVICE);
...
notificationManager.notify(1,myNotification);
}
}
我已经剪切了代码,所有使用的变量都被创建了,我找不到解决方案。如果我没有在意图中放入额外的数据,它可以正常工作,但是当我 putExtra 时它不起作用,因为没有通知。谢谢!!