Android 在手机处于睡眠状态时播放声音

Android 在手机处于睡眠状态时播放声音,android,audio,sleep,audio-player,Android,Audio,Sleep,Audio Player,我正在创建一个服务,它在随机间隔中提醒用户。此服务由活动启动,并作为服务在后台运行 我面临的挑战是,当用户将手机置于睡眠空白屏幕时,在某些情况下声音根本无法播放。时间已过,但声音无法按时播放或在用户唤醒手机时播放 下面是一些代码: /** * Starts a new thread which is checking every seconds how much time has * elapsed and if the point of time has come to play the

我正在创建一个服务,它在随机间隔中提醒用户。此服务由活动启动,并作为服务在后台运行

我面临的挑战是,当用户将手机置于睡眠空白屏幕时,在某些情况下声音根本无法播放。时间已过,但声音无法按时播放或在用户唤醒手机时播放

下面是一些代码:

/**
 * Starts a new thread which is checking every seconds how much time has
 * elapsed and if the point of time has come to play the sound.
 * Once the time has come, it gets the next ring time and continues
 * until it is shut down by the user
 */
private void runCheck() {
    Log.i(tag, "starting runCheck");

    Thread thread = new Thread() {
        public void run() {

            Log.i(tag, "starting LogoTimerThread");
            while (vRunningFlag) {

                try {

                    // update the notification
                    makeNotification();

                    Log.v(tag,
                            "Next Ring in : ["
                                    + helper.TimeCalculator
                                            .duration2_hh_MM_SS((vTimerNextRing - System
                                                    .currentTimeMillis()) / 1000)
                                    + " sec.]");

                    // check if time has run out
                    if (vTimerNextRing < System.currentTimeMillis()) {
                        // reset the timer
                        setNextRingTime();
                        // update the screen
                        makeNotification();
                        // play the sound
                        playLTimerSound();
                    }

                    sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
            Log.i(tag, "finished LogoTimerThread");
        }
    };

    thread.start();
}

在你的场景中,不能获得屏幕模糊唤醒锁定吗

@Override
 protected void onCreate(Bundle icicle) {
     super.onCreate(icicle);




PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "App");
wl.acquire();

}

我必须在播放声音之前或在创建时获得锁吗?我对韦克洛克不太熟悉。
@Override
 protected void onCreate(Bundle icicle) {
     super.onCreate(icicle);




PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "App");
wl.acquire();

}