Add while-idle alarm support to apidemos
Test: Manual test Bug: 72124522 Change-Id: I9d0c0ed4b6a045e4f8f566c4e9844290e850e2fc
This commit is contained in:
@@ -63,6 +63,8 @@ App/Service/Alarm Controller
|
||||
</table>
|
||||
|
||||
*/
|
||||
// Start with:
|
||||
// adb shell am start com.example.android.apis/.app.AlarmController
|
||||
public class AlarmController extends Activity {
|
||||
Toast mToast;
|
||||
|
||||
@@ -75,6 +77,8 @@ public class AlarmController extends Activity {
|
||||
// Watch for button clicks.
|
||||
Button button = (Button)findViewById(R.id.one_shot);
|
||||
button.setOnClickListener(mOneShotListener);
|
||||
button = (Button)findViewById(R.id.one_shot_while_idle);
|
||||
button.setOnClickListener(mOneShotListener);
|
||||
button = (Button)findViewById(R.id.start_repeating);
|
||||
button.setOnClickListener(mStartRepeatingListener);
|
||||
button = (Button)findViewById(R.id.stop_repeating);
|
||||
@@ -99,7 +103,16 @@ public class AlarmController extends Activity {
|
||||
|
||||
// Schedule the alarm!
|
||||
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
|
||||
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
|
||||
|
||||
switch (v.getId()) {
|
||||
case R.id.one_shot:
|
||||
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
|
||||
break;
|
||||
default:
|
||||
am.setExactAndAllowWhileIdle(
|
||||
AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
|
||||
break;
|
||||
}
|
||||
|
||||
// Tell the user about what we did.
|
||||
if (mToast != null) {
|
||||
|
||||
Reference in New Issue
Block a user