Skip to main content

Android Wear Tutorial

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

adb -d forward tcp:5601 tcp:5601


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.
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);

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();

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

Popular posts from this blog

Setting Up Android CheckStyle in Android Studio

So we all want to abide by the Android Code Style Guidelines shown in the official Android developer website here . How do we get started by helping ourselves by abiding by the Java and Android code style rules? Simple. Set it in Android Studio with the instructions below:  1. Copy the file in  https://github.com/android/platform_development/blob/master/ide/intellij/codestyles/AndroidStyle.xml 2. Paste the file into ~/.AndroidStudioPreview/config/codestyles/ (in Ubuntu) or ~/Library/Preferences/AndroidStudioPreview/codestyles (in Mac OS X) 3. Go to Settings (or Preferences in Mac OS X) > Code Style > Java, select AndroidStyle, as well as Code Style > XML and select AndroidStyle. 4. Start code inspection and see the results by selecting Analyze > Inspect Code. You will see the results of inspection on the Inspection pane at the bottom and and you will notice things that you can improve in your Java code such as Code Style Issues, Android, D

How To Reset Android Studio on Mac

Just in case you guys have trouble starting Android Studio for some unknown reason such as clearing the Mac OS cache using a third party tool, these are the steps to troubleshoot the problem. Step 1: Close Android Studio. Step 2: Remove all the directories that are related to Android Studio ~/Library/Application Support/AndroidStudioBeta ~/Library/Caches/ AndroidStudioBeta ~/Library/Logs/ AndroidStudioBeta ~/Library/Preferences/ AndroidStudioBeta Step 3: Start Android Studio Simple as that...

Groovy Grails POST/GET Requests

Just a snippet of how to do GET/POST request in Groovy Grails. try{       HttpBuilder http = new HTTPBuilder('your URL here')       def postBody = [name: 'bob', title: 'construction worker']       http.post(body: postBody,                         requestContentType: ContentType.JSON) { resp, json ->                     //This is to assume everything is successful within this                         //closure                     println "response status " + resp.statusLine                     println "json response " + json                                      } }catch(HttpResponseException ex){         //handle your errors here }