Vibrate an Android Wear device on notification
Asked Answered
T

2

8

I'm trying to develop an app for android and Android Wear (Wear OS). I create a Notification from the mobile to the watch.

notification = new NotificationCompat.Builder(context)
                    .setSmallIcon(icon)
                    .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000, 1000})
                    .setContentTitle(title)
                    .setContentText(content)
                    .setStyle(bigStyle.bigText(content))
                    .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), background))
                    .build();

In the manifest of the watch I set:

<uses-permission android:name="android.permission.VIBRATE"/>

Unfortunately, there is no vibration. How can I fix it?

Thanks.

Telephonic answered 14/10, 2014 at 14:58 Comment(1)
That's unexpected but when I removed the watch from its dock, the watch started to vibrate. I think it blocks the vibrations. Hope it will be helpfulTelephonic
V
9
 .setDefaults(Notification.DEFAULT_ALL)

This line of code will make the wear wake up and vibrate.

Vitreous answered 30/10, 2014 at 22:3 Comment(0)
K
0

I would like to add 1 more updated answer for SDK 26 and above. I spent many hours trying to determine why my notifications would not vibrate on the Android Wear watch.

I eventually noticed that someone had set the priority on the notification channel to IMPORTANCE_MIN.

if (Build.VERSION.SDK_INT >= 26) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel notificationChannel = new NotificationChannel(Config.NOTIFICATION_CHANNEL_ID, Config.NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_MIN);
    notificationManager.createNotificationChannel(notificationChannel);
}

To fix the issue, I did the following:

  • Uninstalled the app from the phone
  • Changed the priority to HIGH [Though I suspect NORMAL will work also]
  • Reinstalled the app

Updated Code:

NotificationChannel(Config.NOTIFICATION_CHANNEL_ID, Config.NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);

Note: You also need to ensure that your defaults are correct as 'Android enthusiast' pointed out in his earlier answer.

I hope it saves someone from an investigation.

Kindhearted answered 13/2, 2019 at 23:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.