Display notification on Android Wear without showing it on the phone

    Nevertheless, I decided, despite my skepticism, to start porting 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 on the clock can be sent only by a trailer to the system-wide Android notification. On Sony, everything was divided and even too much, but here everything is integrated and by itself works. Nailed nailed.

    Quick googling did not lead to results - old hacks were already thrown out of the latest versions of the API and I was already starting to think to programmatically 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.

    Things went further, came to the merger of notifications, for convenience. And here I was attracted by the phrase:
    It's important that you still provide a summary notification that appears on handheld devices.

    I decided to try, and what will happen if I do not specify either BigContentTitle or Summary, but only indicate the group:

    	    NotificationCompat.Builder notificationBuilder =
    	            new NotificationCompat.Builder(getApplicationContext())

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

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

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

    Also popular now: