安卓磨损 : Programmatically Wake Screen

标签 android wear-os

有谁知道我将如何唤醒 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/

相关文章:

android - Google Fit API : ApiException 17 (Fitness. 客户端在此设备上不可用)

安卓磨损 : launching an activty in the handheld on clicking notification action button in wear

android - 无法在 Wear OS 上注册新磁贴

php - Android登录mysql数据库

java - 实例化一个类,然后在另一个线程中使用它

Android MediaPlayer setDataSource() 抛出 IllegalStateException 错误

android - 在 Android Wear 上保持应用唤醒

java - 如何在服务器中创建上传数据队列并根据ID获取已上传数据的轨迹

android - 未找到类 "androidx.constraintlayout.ConstraintLayout"

android - Android Wear 2.0有自己的GCM/FCM注册ID吗?