2

I have Created a project for android wear devices. I need to customize the notification style on the wearable device. Is there any method for that.

My method is

Intent displayIntent = new Intent(getApplicationContext(), CustomNotification.class);
 PendingIntent displayPendingIntent = PendingIntent.getActivity(getApplicationContext(),
         0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification =
            new NotificationCompat.Builder(context)
                    .extend(new WearableExtender()
                            .setDisplayIntent(displayPendingIntent))
                            .build();

    int notificationId = 001;

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager =
            NotificationManagerCompat.from(this);

    notificationManager.notify(notificationId , notification);

But i didn't get a notification.

Is there any method to customize with my custom layout design?

and this is the manifest part

 <activity android:name="com.client.android.CustomNotification"
     android:exported="true"
     android:allowEmbedded="true"
     android:taskAffinity=""
     android:theme="@android:style/Theme.DeviceDefault.Light" />
ranjith
  • 4,526
  • 5
  • 27
  • 31

1 Answers1

4

Please take a look at the official documentation about creating custom notifications on Android Wear.

Use Big View:

You can apply styles to your notificaitons, such as BigPictureStyle, BigTextStyle or InboxStyle.

Here is an example of using BigTextStyle:

// Specify the 'big view' content to display the long
// event description that may not fit the normal content text.
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText(eventDescription);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.ic_event)
    .setLargeIcon(BitmapFractory.decodeResource(getResources(), R.drawable.notif_background))
    .setContentTitle(eventTitle)
    .setContentText(eventLocation)
    .setContentIntent(viewPendingIntent)
    .addAction(R.drawable.ic_map, getString(R.string.map), mapPendingIntent)
    .setStyle(bigStyle);

More info:
http://developer.android.com/training/wearables/notifications/creating.html#BigView

Use custom notification layout:

You can create a layout in your Activity and embed it inside your notification: https://developer.android.com/training/wearables/apps/layouts.html#CustomNotifications

NOTE: Please notice that this approach has some restrictions and will only work for notifications submitted directly from Android Wear device (not from phone).

Please also read the note at the end of that tutorial:

Note: When the notification is peeking on the homescreen, the system displays it with a standard template that it generates from the notification's semantic data. This template works well on all watchfaces. When users swipe the notification up, they'll then see the custom activity for the notification.

Maciej Ciemięga
  • 10,125
  • 1
  • 41
  • 48
  • I tried the method which described there, but it doesn't give the result. – ranjith Jul 24 '14 at 11:45
  • It seems that you've implemented something not right:) Maybe you will post some code? – Maciej Ciemięga Jul 24 '14 at 11:47
  • I have implmented, what they telling in 4th step is Build a Notification and call setDisplayIntent(), this is used for open a view when user swipe the notification on the wear device. – ranjith Jul 24 '14 at 11:51
  • 1
    ...and what was your result? In your original code you haven't set the `setDisplayIntent` anywhere. Please update code in question to new one. Also post the manifest with declared `Activity`. – Maciej Ciemięga Jul 24 '14 at 11:55
  • I think that the `setSmallIcon` and at least `setContentTitle` are necessary in order to show a notification at all. – Maciej Ciemięga Jul 24 '14 at 12:09
  • Its only comes when swipe that. When I swipe the desired custom notification came. Is there any method it comes automatically? – ranjith Jul 24 '14 at 12:17
  • No. Please read the in tutorial: **Note**: When the notification is peeking on the homescreen, the system displays it with a standard template that it generates from the notification's semantic data. This template works well on all watchfaces. When users swipe the notification up, they'll then see the custom activity for the notification. – Maciej Ciemięga Jul 24 '14 at 12:20
  • Ya I saw that, But is there any method to see custom notification first? – ranjith Jul 24 '14 at 12:23
  • 1
    No. Not at this moment. Maybe something like that will be added in next version of API... maybe not... who knows:) – Maciej Ciemięga Jul 24 '14 at 12:24
  • Thats fine...Thanks for helping me. – ranjith Jul 24 '14 at 12:31
  • No problem. I really hope that they will figure out some way to customize the notifications better. The same way as standard Android Wear cards do, like Weather, Calendar etc... But they are build-in and have different restrictions. – Maciej Ciemięga Jul 24 '14 at 12:35