I. Preface description
Add the Android Wear notification feature in the previous section we have implemented a simple Android Wear card extension, but the default number of cards provided to us can only achieve a simple text display, if you want to customize the layout, add pictures and so on, you need the knowledge of this section.
Two. Environment Configuration
- Code configuration is no different from the previous section
- If you use the Wear simulator to develop, you must pay attention to the configuration, the use of the Host GPU must be hooked, otherwise, the dynamic custom card will not display, into a black block.
Three. Custom Cards
- Figure 1~4 Card display: can set the card height, can adjust the display content style
- Figure 5 Card display: Animation effect, here is actually a non-stop moving card
So we can see that the custom cards can do things that are many and many.
Code implementation
PrivateNotification Getcustomextender () {//1. Build a pendingintent that specifies activityIntent displayintent=NewIntent ( This, Secondactivity.class); Pendingintent displaypendingintent= Pendingintent.getactivity ( This,0, Displayintent, pendingintent.flag_update_current); //2. Build a wear extension object and set the pendingintent to show activityWearableextender Extender=NewNotificationcompat.wearableextender (); Extender.setdisplayintent (displaypendingintent); //3. Build a Notificationcompat.builder, fill in the relevant parameters, and return the notification objectNotificationcompat.builder Builder=NewNotificationcompat.builder ( This); Builder.setcontenttitle ("title"); Builder.setcontenttext ("text"); Builder.extend (extender); returnbuilder.build ();}
It is then added to the card in the form of adding a new page card.
Wearableextender.addpage (Getcustomextender ());
Android Wear Development-card Notifications-section II: Custom Wear card styles