📜 ⬆️ ⬇️

Display notification on Android Wear, without showing it on the phone

I decided all the same, despite my skepticism, to start transferring applications to Android Wear.

The first thing is to show notifications, IMHO, the first and most important function of a smart watch.
I open the manual and find out that notifications for watches can only be sent by a trailer to the system-wide Android notification. On Sony, everything was divided and even too much, but here everything is integrated and works by itself. Nails nailed.

Fast googling did not lead to results - the old hacks had already been thrown out of the latest versions of the API and I had already begun to think programmatically to hide the notification on the phone. But then I remembered that when you hide a notification on a watch or phone - it automatically hides on another device. I decided to score.
')
The case went further, reached the consolidation of notifications , for convenience. And here I was attracted by the phrase:
It is important that you still provide handheld devices.

I decided to try, and what will happen if I don’t specify either BigContentTitle or Summary, but only specify the group:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.icon_extension) .setContentTitle(title) .setContentText(message) .setGroup(group); 

And then, suddenly, the notification seemed on the clock, but nothing was displayed on the phone! There are no errors in logcat, no brakes occur, everything works just fine:



If you do not need to combine notifications, then you can simply specify the same identifier as a group when calling notificationManager.notify

Here is such a small hack for Wear-developers, I hope this will be useful to many.

Source: https://habr.com/ru/post/236721/


All Articles