Reputation: 16354
In handheld devices, custom notifications can be displayed using RemoteViews. RemoteViews allows the developer to fully customise the notification.
What is the way to do the same for Android Wear? Which class should be used to override the default notification UI with my own customised one?
Upvotes: 1
Views: 2138
Reputation: 285
if you want to customize text only, you can use SpannableString. It allows you to change color, background, align of your title/content text.
if you want to create totally different notification you have to implement smth similar 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 - activity container of you custom view.
NOTE: you HAVE TO use .setSmallIcon(..)
even if you don't need it.
Seems like a google bug, but without this line notification won't be shown.
and set
android:allowEmbedded="true"
android:taskAffinity=""
for your activity container
Upvotes: 4
Reputation: 10383
Currently there is no way to do that. EDIT: it is possible: Custom UI for Android Wear Notifications
Best option out there are:
NotificationCompat.WearableExtender
notification for both phone and Wear.setLocalOnly()
so notification will be limited to phone, and on Wear create separate one - with other look, actions etc.So only last option allows you to have custom layout but there are many drawback (as it is own app) - for example it is separate from notification list.
Hope that might change in the future.
Upvotes: 0
Reputation: 13019
To create a rich Notification for Android Wear, you have to use NotificationCompat.Builder
from support-v4.
This version gives you a better control of the notification layout on Wear with methods such as .setActionButton()
or .setStyle()
.
You can even more customize your notification with a NotificationCompat.WearableExtender
.
Learn more at Creating a Notification
Upvotes: 1