有谁知道我将如何唤醒 Wear 屏幕?我正在运行振动 API:
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate( getResources().getInteger( R.integer.vibration_duration ) );
应该在 2 秒(2000 毫秒)后停止。这在屏幕打开时效果很好,但如果屏幕关闭,振动将继续,直到屏幕被触摸并唤醒。
编辑: 我确实整理了一个快速 hack 以使其与计时器一起工作,但我希望能够以更干净的方式停止振动。
final Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate( getResources().getInteger( R.integer.vibration_duration ) );
Timer timer = new Timer();
timer.schedule( new TimerTask() {
@Override
public void run() {
v.cancel();
}
}, getResources().getInteger( R.integer.vibration_duration ) );
重新编辑:这并不是每次都有效,太棒了,能够唤醒屏幕是最好的选择。我确实通过使用模式而不是直接输入持续时间来让它工作,但我仍然很想知道如何激活屏幕,因为我觉得这可能会导致更多问题,因为我继续使用这个平台.
long[] pattern = { 0, getResources().getInteger( R.integer.vibration_duration ) };
v.vibrate( pattern, -1 );
最佳答案
使用 NotificationCompat.Builder 为您的应用创建通知并包含振动模式。这应该会通过您的通知唤醒屏幕(并且仍然会为用户振动)。可穿戴设备主动返回 sleep 状态,尤其是在用户不与其交互的情况下,因此这可能是最简单的方法。
关于安卓磨损 : Programmatically Wake Screen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24518010/