Vibration triggered by alarm when device is asleep doesn't stop
I'm rather wondering if this is specific to my device (Nexus 4, Android
4.3, stock ROM), but I have an alarm, registered once via the
AlarmManager. When triggered, the device is set to vibrate for two
seconds. If the alarm is triggered while the device is on, then it
correctly vibrates for the two seconds. However, if the alarm is triggered
when the device is off (and unplugged), the vibration starts, but doesn't
stop until the power button is pressed (to wake up the device). Here is
the code to register the alarm:
public static void registerAlarm(Context context, int uniqueId, long
triggerAlarmAt)
{
Intent intent = new Intent(context, AlarmReceiver.class);
intent.setAction("com.myapp.ALARM_EVENT");
PendingIntent pendingIntent =
PendingIntent.getBroadcast(context.getApplicationContext(), uniqueId,
intent, 0);
AlarmManager alarmManager = (AlarmManager)
context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, triggerAlarmAt, pendingIntent);
}
And the receiver code:
public class AlarmReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent arg1)
{
Vibrator vibrator = (Vibrator)
context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(2000);
}
}
Any ideas on why this is happening or how to prevent it?
No comments:
Post a Comment