Top Banner
Android Wear Notification +Anuchit Chalothorn [email protected]
24

01 Android Wear Notification

Jul 14, 2015

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 01 Android Wear Notification

Android WearNotification

+Anuchit [email protected]

Page 2: 01 Android Wear Notification

Android Wear Notification

Mobile App can send notification to Android Wear device just using NotificationCompat all notification sent to device.

Page 3: 01 Android Wear Notification

Notification

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

builder.setContentTitle("Notification Title");

builder.setContentText("Notification Text");

builder.setSmallIcon(R.drawable.ic_launcher)

NotificationManagerCompat manager = NotificationManagerCompat.from(this);

manager.notify(1,builder.build());

Page 4: 01 Android Wear Notification
Page 5: 01 Android Wear Notification

Notification Pending Intent

You can add card and use it as a button to call other activity by using pending intent.

Page 6: 01 Android Wear Notification

Notification Pending Intent

Intent intent = new Intent(this,NotificationActivity.class);

PendingIntent pendingIntent =

PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT)

Add new intent to your activity and set into pending intent object

Page 7: 01 Android Wear Notification

Notification Pending Intent

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

builder.setContentTitle("Notification Title");

builder.setContentText("Notification Text");

builder.setSmallIcon(R.drawable.ic_launcher);

builder.setContentIntent(pendingIntent);

NotificationManagerCompat manager = NotificationManagerCompat.from(this);

manager.notify(1,builder.build());

Page 8: 01 Android Wear Notification
Page 9: 01 Android Wear Notification
Page 10: 01 Android Wear Notification

Page Notification

You can add more peek card using more notification and use notification extend to add more page.

Page 11: 01 Android Wear Notification

Page Notification

Intent intent = new Intent(this,NotificationActivity.class);

PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

Page 12: 01 Android Wear Notification

Page Notification

// First Notification

NotificationCompat.Builder firstBuilder = new NotificationCompat.Builder(this);

firstBuilder.setContentTitle("First Notification Title");

firstBuilder.setContentText("First Notification Text");

firstBuilder.setSmallIcon(R.drawable.ic_launcher);

firstBuilder.setContentIntent(pendingIntent);

Page 13: 01 Android Wear Notification

Page Notification

// Second Notification

NotificationCompat.Builder secondBuilder = new NotificationCompat.Builder(this);

secondBuilder.setContentTitle("Second Notification Title");

secondBuilder.setContentText("Second Notification Text");

secondBuilder.setSmallIcon(R.drawable.ic_launcher);

// Set Second Notification

Notification secondNotification = secondBuilder.build();

Page 14: 01 Android Wear Notification

Page Notification

// Extend Notification

Notification extendNotification = firstBuilder.extend(new NotificationCompat.WearableExtender().addPage(secondNotification)).build();

NotificationManagerCompat manager = NotificationManagerCompat.from(this);

manager.notify(1,extendNotification);

Page 15: 01 Android Wear Notification
Page 16: 01 Android Wear Notification

Notification Action

Notification in mobile can add action to notification, in Android Wear device will show as action button so you can set intent to this button.

Page 17: 01 Android Wear Notification

Notification Action

// Default Intent

Intent intent = new Intent(this,NotificationActivity.class);

PendingIntent pendingIntent =

PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

Page 18: 01 Android Wear Notification

Notification Action

// Map Intent

Intent mapIntent = new Intent(Intent.ACTION_VIEW);

mapIntent.setData(Uri.parse("geo:0,0?q=13.744033,100.494384(National Discovery Museum Institute)&z=17"));

PendingIntent mapPendingIntent = PendingIntent.getActivity(this,1,mapIntent,0);

Page 19: 01 Android Wear Notification

Notification Action

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

builder.setContentTitle("National Discovery Museum Institute");

builder.setContentText(" ...");

builder.setSmallIcon(R.drawable.ic_launcher);

builder.setContentIntent(pendingIntent);

builder.addAction(R.drawable.ic_map,"Open Map",mapPendingIntent);

Page 20: 01 Android Wear Notification

Notification Action

NotificationManagerCompat manager = NotificationManagerCompat.from(this);

manager.notify(1,builder.build());

Page 21: 01 Android Wear Notification
Page 22: 01 Android Wear Notification
Page 23: 01 Android Wear Notification
Page 24: 01 Android Wear Notification

Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Thank You