So Android Wear is going to be announced in hours at the Google I/O 2014 event.
To get started with Android Wear, follow these steps (You must sign up to the Android Wear Developer Preview, download the Android Wear Preview jar file and add the library to your project in order to continue):
1. Set up the Android Wear emulator after downloading the Android Wear System Image and related Android Wear packages from the Android SDK Manager
2. Start the emulator.
3. Download the Android Wear Preview app after opting in as a tester.
4. Use this command to connect the emulator to your phone via USB
Simple Example of Wearable Notification
1. Create a sample notification using this template. Notice that I've wrapped up notificationBuilder with WearableNotifications.Builder.
2. NotificationManagerCompat is mandatory to ensure code compatibility with lower versions of Android.
3.
Actions
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.addAction(R.drawable.ic_launcher, "Reply", pendingIntent)
.setContentText("Hello World!");
This reflects on the phone's status bar notification, as well as the Android Wear emulator.
Page Notifications
1. Create a second page notification
// Create a big text style for the second page
NotificationCompat.BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
secondPageStyle.setBigContentTitle("Page 2")
.bigText("A lot of text...");
// Create second page notification
Notification secondPageNotification =
new NotificationCompat.Builder(this)
.setStyle(secondPageStyle)
.build();
Notification notification =
new WearableNotifications.Builder(mBuilder)
.addPage(secondPageNotification)
.build();
Stack Notifications
1. Set up a summary notification using WearableNotifications.Builder.
Notification summaryNotification = new WearableNotifications.Builder(mBuilder)
.setGroup(GROUP_KEY_SAMPLE, WearableNotifications.GROUP_ORDER_SUMMARY)
.build();
To get started with Android Wear, follow these steps (You must sign up to the Android Wear Developer Preview, download the Android Wear Preview jar file and add the library to your project in order to continue):
1. Set up the Android Wear emulator after downloading the Android Wear System Image and related Android Wear packages from the Android SDK Manager
2. Start the emulator.
3. Download the Android Wear Preview app after opting in as a tester.
4. Use this command to connect the emulator to your phone via USB
adb -d forward tcp:5601 tcp:5601
1. Create a sample notification using this template. Notice that I've wrapped up notificationBuilder with WearableNotifications.Builder.
2. NotificationManagerCompat is mandatory to ensure code compatibility with lower versions of Android.
3.
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_event) .setContentTitle(eventTitle) .setContentText(eventLocation) .setContentIntent(viewPendingIntent); Notification notification = new WearableNotifications.Builder(notificationBuilder) .build(); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(notificationId, notification);
Actions
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.addAction(R.drawable.ic_launcher, "Reply", pendingIntent)
.setContentText("Hello World!");
This reflects on the phone's status bar notification, as well as the Android Wear emulator.
Page Notifications
1. Create a second page notification
// Create a big text style for the second page
NotificationCompat.BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle();
secondPageStyle.setBigContentTitle("Page 2")
.bigText("A lot of text...");
// Create second page notification
Notification secondPageNotification =
new NotificationCompat.Builder(this)
.setStyle(secondPageStyle)
.build();
Notification notification =
new WearableNotifications.Builder(mBuilder)
.addPage(secondPageNotification)
.build();
notificationManagerCompat.notify(notificationId1, notification);
1. Set up a summary notification using WearableNotifications.Builder.
Notification summaryNotification = new WearableNotifications.Builder(mBuilder)
.setGroup(GROUP_KEY_SAMPLE, WearableNotifications.GROUP_ORDER_SUMMARY)
.build();
2. Specify one or more notifications. Remember to add setGroup to the notifications.
// Create a WearablesNotification.Builder to add special functionality for wearables
Notification notification =
new WearableNotifications.Builder(mBuilder)
.setGroup(GROUP_KEY_SAMPLE)
//.addPage(secondPageNotification)
.build();
// Use the same group as the previous notification
Notification notif2 = new WearableNotifications.Builder(mBuilder2)
.setGroup(GROUP_KEY_SAMPLE)
.build();
3. Show the notification.
notificationManagerCompat.notify(notificationId1, summaryNotification);
notificationManagerCompat.notify(notificationId2, notification);
notificationManagerCompat.notify(notificationId3, notif2);
Source code to the sample :
Source :
Comments
Post a Comment