在警报管理器中传递值

Kan*_*dha 5 android

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

Pau*_*rke 7

Use a PendingIntent, whose Intent has bundled extras.

This is modified from the 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);
Run Code Online (Sandbox Code Playgroud)

Then retrieve those in your Receiver's onReceive():

intent.getStringExtra("some_name")
Run Code Online (Sandbox Code Playgroud)