Android Wear: custom notifications

On portable devices, custom notifications can be displayed using RemoteViews . RemoteViews allows the developer to fully customize the notification.

What is the way to do the same for Android Wear? Which class should I use to override the default notification user interface with my own configured?

+1
source share
3 answers
  • If you want to customize only text, you can use SpannableString. It allows you to change the color, background, align the text of the header / content.

  • if you want to create a completely different notification, you need to implement smth-like in your wear project

    Intent notificationIntent = new Intent(context, WearNotificationActivity.class); PendingIntent pendingNotificationIntent = PendingIntent.getActivity(context, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification.Builder(context) .setSmallIcon(R.drawable.ic_launcher) // .setContentTitle("CustomNotification") .extend(new Notification.WearableExtender() .setDisplayIntent(pendingNotificationIntent) .setCustomSizePreset(Notification.WearableExtender.SIZE_LARGE) .setStartScrollBottom(false) .setHintHideIcon(true)) .build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); 

where WearNotificationActivity is the activity container of your custom view.

NOTE: you need to use .setSmallIcon(..) , even if you do not need it. It seems that the error is Google, but without this notification the line will not be displayed.

and install

  android:allowEmbedded="true" android:taskAffinity="" 

for your activity container

+4
source

To create a rich notification for Android Wear, you must use NotificationCompat.Builder from support-v4.

This version gives you better control over the layout of Wear notifications using methods such as .setActionButton() or .setStyle() .

You can even customize your notification using NotificationCompat.WearableExtender .

Read more about Creating Notifications

+1
source

There is currently no way to do this. EDIT: Possible: User Interface for Android Wear Notifications

The best way:

  • Create a notification on the phone and use the NotificationCompat.WearableExtender NotificationCompat.WearableExtender for the phone and Wear.
  • Create a notification using setLocalOnly() , so the notification will be limited to the phone, and on Wear, create a separate one with a different look, actions, etc.
  • Do as described above, but instead of wearing a notification on Wear, create your own application using CardFrames (which allows you to have a “notification style” and a custom layout at the same time, and when receiving a signal from your phone, launch the application instead of a notification.

Thus, only the last parameter allows you to have a custom layout, but there are many drawbacks (since this is your own application) - for example, it is separated from the list of notifications.

Hope this may change in the future.

0
source

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


All Articles