在警报管理器中传递值

时间:2010-09-07 04:36:24

标签: android

我们怎样才能将值传递给接收者......我正在使用闹钟管理器...

1 个答案:

答案 0 :(得分:7)

使用PendingIntentIntent已捆绑附加内容。

这是从AlarmController Google APIDemo

修改的
Intent intent = new Intent(AlarmController.this, RepeatingAlarm.class);
intent.putExtra("some_name", some_value);
PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this,0, intent, 0);

// We want the alarm to go off 30 seconds from now.
long firstTime = SystemClock.elapsedRealtime();
firstTime += 15*1000;

// Schedule the alarm!
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,firstTime, 15*1000, sender);

然后检索接收者onReceive()中的那些:

intent.getStringExtra("some_name")