Add while-idle alarm support to apidemos
Test: Manual test Bug: 72124522 Change-Id: I9d0c0ed4b6a045e4f8f566c4e9844290e850e2fc
This commit is contained in:
@@ -33,6 +33,12 @@
|
|||||||
<requestFocus />
|
<requestFocus />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<Button android:id="@+id/one_shot_while_idle"
|
||||||
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
|
android:text="@string/one_shot_while_idle_alarm">
|
||||||
|
<requestFocus />
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button android:id="@+id/start_repeating"
|
<Button android:id="@+id/start_repeating"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||||
android:text="@string/start_repeating_alarm" />
|
android:text="@string/start_repeating_alarm" />
|
||||||
|
|||||||
@@ -348,6 +348,7 @@
|
|||||||
<string name="alarm_controller">This demonstrates how to schedule and handle
|
<string name="alarm_controller">This demonstrates how to schedule and handle
|
||||||
one-shot and repeating alarms.</string>
|
one-shot and repeating alarms.</string>
|
||||||
<string name="one_shot_alarm">One Shot Alarm</string>
|
<string name="one_shot_alarm">One Shot Alarm</string>
|
||||||
|
<string name="one_shot_while_idle_alarm">One Shot While-Idle Alarm</string>
|
||||||
<string name="start_repeating_alarm">Start Repeating Alarm</string>
|
<string name="start_repeating_alarm">Start Repeating Alarm</string>
|
||||||
<string name="stop_repeating_alarm">Stop Repeating Alarm</string>
|
<string name="stop_repeating_alarm">Stop Repeating Alarm</string>
|
||||||
<string name="one_shot_scheduled">One-shot alarm will go off in 30 seconds based on
|
<string name="one_shot_scheduled">One-shot alarm will go off in 30 seconds based on
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ App/Service/Alarm Controller
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
// Start with:
|
||||||
|
// adb shell am start com.example.android.apis/.app.AlarmController
|
||||||
public class AlarmController extends Activity {
|
public class AlarmController extends Activity {
|
||||||
Toast mToast;
|
Toast mToast;
|
||||||
|
|
||||||
@@ -75,6 +77,8 @@ public class AlarmController extends Activity {
|
|||||||
// Watch for button clicks.
|
// Watch for button clicks.
|
||||||
Button button = (Button)findViewById(R.id.one_shot);
|
Button button = (Button)findViewById(R.id.one_shot);
|
||||||
button.setOnClickListener(mOneShotListener);
|
button.setOnClickListener(mOneShotListener);
|
||||||
|
button = (Button)findViewById(R.id.one_shot_while_idle);
|
||||||
|
button.setOnClickListener(mOneShotListener);
|
||||||
button = (Button)findViewById(R.id.start_repeating);
|
button = (Button)findViewById(R.id.start_repeating);
|
||||||
button.setOnClickListener(mStartRepeatingListener);
|
button.setOnClickListener(mStartRepeatingListener);
|
||||||
button = (Button)findViewById(R.id.stop_repeating);
|
button = (Button)findViewById(R.id.stop_repeating);
|
||||||
@@ -99,7 +103,16 @@ public class AlarmController extends Activity {
|
|||||||
|
|
||||||
// Schedule the alarm!
|
// Schedule the alarm!
|
||||||
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
|
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.
|
// Tell the user about what we did.
|
||||||
if (mToast != null) {
|
if (mToast != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user