相关疑难解决方法(0)

Android无法通过AlarmManager传递intent附加功能

我试图在我的意图中添加一条额外的消息,以便传递给稍后触发的AlarmManager.我的onReceive正确触发,但extras.getString()返回null

建立:

public PendingIntent getPendingIntent(int uniqueRequestCode, String extra) {
    Intent intent = new Intent(this, ActionReceiver.class);
    intent.putExtra("EXTRA", extra);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, uniqueRequestCode,
            intent, 0);
    return pendingIntent;
}

public void setSilentLater(TimeRule timeRule) {
    boolean[] weekdays = timeRule.getReoccurringWeekdays();
    int dayOfWeek = 0;

    for (boolean day : weekdays) {
        dayOfWeek++;
        if (day == true) {
            Calendar cal = Calendar.getInstance();

            AlarmManager alarmManager = (AlarmManager) this
                    .getSystemService(Context.ALARM_SERVICE);

            cal.set(Calendar.DAY_OF_WEEK, dayOfWeek);
            cal.set(Calendar.HOUR_OF_DAY,
                    timeRule.getStartTime().get(Calendar.HOUR_OF_DAY));
            cal.set(Calendar.MINUTE,
                    timeRule.getStartTime().get(Calendar.MINUTE));
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                    cal.getTimeInMillis(), 3600000 * 7, getPendingIntent(0, "RINGER_OFF"));
  } …
Run Code Online (Sandbox Code Playgroud)

android broadcastreceiver alarmmanager android-pendingintent android-bundle

44
推荐指数
2
解决办法
2万
查看次数