我们怎样才能将值传递给接收者......我正在使用闹钟管理器...
答案 0 :(得分:7)
使用PendingIntent
,Intent
已捆绑附加内容。
这是从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")