Add while-idle alarm support to apidemos

Test: Manual test
Bug: 72124522
Change-Id: I9d0c0ed4b6a045e4f8f566c4e9844290e850e2fc
This commit is contained in:
Makoto Onuki
2018-01-30 12:58:20 -08:00
parent e1c924c9e5
commit 10d6c41f9b
3 changed files with 21 additions and 1 deletions

View File

@@ -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) {