开发者

pass values in alarm manager

开发者 https://www.devze.com 2023-01-14 21:31 出处:网络
h开发者_StackOverflowow can we pass the value to receiver...i am using alarm manager...Use a PendingIntent, whose Intent has bundled extras.

h开发者_StackOverflowow can we pass the value to receiver...i am using alarm manager...


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);

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

intent.getStringExtra("some_name")
0

精彩评论

暂无评论...
验证码 换一张
取 消