Back to project page Android.Wear.Message.
The source code is released under:
MIT License
If you think the Android project Android.Wear.Message listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.iamnbty.androidwear; /*w w w. j a va2 s . c o m*/ import android.app.PendingIntent; import android.content.Intent; import android.graphics.BitmapFactory; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationManagerCompat; import com.google.android.gms.wearable.MessageEvent; import com.google.android.gms.wearable.WearableListenerService; public class MessageListenerService extends WearableListenerService { private static final int NOTIFICATION_ID = 001; @Override public void onMessageReceived(MessageEvent messageEvent) { super.onMessageReceived(messageEvent); String path = messageEvent.getPath(); byte[] data = messageEvent.getData(); String sourceNodeId = messageEvent.getSourceNodeId(); notify(path, sourceNodeId, data); } private void notify(String title, String text, byte[] data) { Intent intent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(title) .setContentText(text) .setContentIntent(pendingIntent); if (data != null) { NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender() .setBackground(BitmapFactory.decodeByteArray(data, 0, data.length)); notificationBuilder.extend(wearableExtender); } NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); } }