Is it possible to have a notification that shows a different text (content title and content text) in the Android wear device and in the mobile device?
问题:
回答1:
Not at the moment. However, you can achieve this effect in the following way:
- post a notification on the phone with
setLocalOnly(true)
- post a
DataItem
using aDataAPI
that describes the notification and changed text - when the wearable receives the
DataItem
, post the notification with different text, again settingsetLocalOnly(true)
- on each notification alse call
setDeleteIntent
so you know, when there are dismissed - when on of the notifications gets dismissed, delte the
DataItem
from point 2. - when the
DataItem
gets deleted, you will receive a callback; delete the remaining notification
There might be some corner cases here I don't see immediately, but the general approach should allow you to achieve what you want.
回答2:
Yes, it's possible now with little tricky and bug on Android wear which help's us. More Over this trick doesn't need Android wear API, just a normal Notification with RemoteViews is enough.
NotificationCompat.Builder mBuilder;
mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentText("This msg won't display in your phone, only on wear you can see.")
.setContentTitle("Hello")
.setContentIntent(
PendingIntent.getActivity(context, 10,intent,PendingIntent.FLAG_ONE_SHOT));
NotificationManager mNM = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = mBuilder.build();
RemoteViews contentView = new RemoteViews(context.getPackageName(),
R.layout.notification_layout);
contentView.setTextViewText(R.id.noti_text,"This message won't display in your wear device, only on phone you can see.");
contentView.setImageViewResource(R.id.noti_image,R.drawable.ic_launcher);
notification.contentView = contentView;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNM.notify(50, notification);
Now run the app on your device and check the notification on both watch and phone, the content inside the RemoteViews won't display in your watch but on phone it will display and if you remove the .setContentTitle() & .setContentText(), then the RemoteViews content will be displayed on both watch and phone too.
回答3:
Actually you can achieve this using
.setGroup(GROUP_KEY)
.setGroupSummary(true)
On your phone notification. Then create a notification with the data that you want to show on the watch and set
.setGroup(GROUP_KEY)
to the same group that your phone notification. This is used to show stack notifications but if you use it with only one then it does the trick.
Complete documentation: Stacking Notifications