Android Wear:以编程方式唤醒屏幕

Pau*_*uiz 6 android wear-os

有谁知道如何醒来磨损屏幕?我正在运行振动API:

Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate( getResources().getInteger( R.integer.vibration_duration ) );
Run Code Online (Sandbox Code Playgroud)

应在2秒(2000毫秒)后停止.如果屏幕打开,这种方法很有效,但如果屏幕关闭,则振动将继续,直到屏幕被触摸并唤醒.

编辑:我确实拼凑了一个快速的黑客,让它与计时器一起工作,但我希望能够以更清洁的方式停止振动.

    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 ) );
Run Code Online (Sandbox Code Playgroud)

Reedit:这不是每次都有效,所以是的,能够唤醒屏幕将是最好的选择.我确实通过使用模式而不是直接放入持续时间来使用它,但我仍然想知道如何激活屏幕,因为我觉得这可能会导致更多问题,因为我一直在使用这个平台.

    long[] pattern = { 0, getResources().getInteger( R.integer.vibration_duration ) };
    v.vibrate( pattern, -1 );
Run Code Online (Sandbox Code Playgroud)

Lar*_*fer 3

使用NotificationCompat.Builder为您的应用程序创建通知并包含振动模式。这应该会通过您的通知唤醒屏幕(并且仍然为用户振动)。可穿戴设备会积极返回睡眠状态,特别是在用户不与其交互的情况下,因此这可能是最简单的方法。