0
我正在为我的android手机设置闹钟应用程序,我想知道是否有可能在设备锁定并且计时器耗尽时播放声音当设备被锁定时是否可以播放声音?
我正在为我的android手机设置闹钟应用程序,我想知道是否有可能在设备锁定并且计时器耗尽时播放声音当设备被锁定时是否可以播放声音?
是的。在Android上,这样对每实时时钟安排唤醒:
private static final long WINDOW_MS = 50L; // Allow some time flexibility to save battery power.
AlarmManager alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = makeAlarmPendingIntent(context);
long nextReminder = ... // the SystemClock.elapsedRealtime() for the next reminder notification
alarmMgr.setWindow(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextReminder - WINDOW_MS,
WINDOW_MS, pendingIntent);
随着BroadcastReceiver
获得这个pendingIntent
。当相关的Intent
到达时,使用Notification
播放声音。见NotificationCompat.Builder
及其setSound()
方法。
Cordova可能会提供所需的API来执行此操作。如果没有,你必须在应用程序的Java部分实现它。