01 Android Wear Notification
-
Upload
anuchit-chalothorn -
Category
Technology
-
view
175 -
download
0
Transcript of 01 Android Wear Notification
Android Wear Notification
Mobile App can send notification to Android Wear device just using NotificationCompat all notification sent to device.
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());
Notification Pending Intent
You can add card and use it as a button to call other activity by using pending intent.
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
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 Notification
You can add more peek card using more notification and use notification extend to add more page.
Page Notification
Intent intent = new Intent(this,NotificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
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 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 Notification
// Extend Notification
Notification extendNotification = firstBuilder.extend(new NotificationCompat.WearableExtender().addPage(secondNotification)).build();
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(1,extendNotification);
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.
Notification Action
// Default Intent
Intent intent = new Intent(this,NotificationActivity.class);
PendingIntent pendingIntent =
PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
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);
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);
Notification Action
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(1,builder.build());
Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Thank You