简体   繁体   中英

Wear OS Notification Vibration and Sound

In my foreground service I get notifications and this is working totally fine. The only problem is that my watch don't vibrate or make any sound when I get a notification. I tried setting vibration on NotificationChannel or on Notification but neither works. Device is a Huawei Watch 2.

NotificationsChannels:

private void createNotificationChannels() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel serviceChannel = new NotificationChannel(
                CHANNEL_ID,
                "Service Channel",
                NotificationManager.IMPORTANCE_LOW
        );
        serviceChannel.setDescription("Foreground Service");

        NotificationChannel messageChannel= new NotificationChannel(
                message_CHANNEL_ID,
                "messages Channel",
                NotificationManager.IMPORTANCE_HIGH
        );
        messageChannel.setDescription("message Channel");
        messageChannel.enableVibration(true);
        messageChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        messageChannel.setVibrationPattern(new long[] {2000});


        NotificationManager manager = getSystemService(NotificationManager.class);
        manager.createNotificationChannel(serviceChannel);
        manager.createNotificationChannel(messageChannel);

    }

Notifications from service:

private void runNotification(Datamodel data)
{
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    Notification notification = new NotificationCompat.Builder(this, messageChannel)
            .setSmallIcon(R.drawable.alarm)
            .setContentTitle(data.getline1())
            .setContentText(data.getline2())
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(Html.fromHtml(data.toString(), FROM_HTML_MODE_COMPACT)))
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setColor(Color.parseColor("#009999"))
            //.setSound(defaultSoundUri)
            //.setCategory(NotificationCompat.CATEGORY_ALARM)
            //.setVibrate(new long[]{2000})
            .build();

    notificationManager.notify(NOTIFICATION_ID, notification);

    NOTIFICATION_ID++;

}

Manifest:

<uses-feature android:name="android.hardware.type.watch" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.VIBRATE"/>

I had the exactly the same problem and watch model. When you test the notifications, wearing the watch on your wirst instead of let it connected to the computer with cable. It works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM