如何创建通知是对设备的磨损不同? [英] How can I create notification that is different on device and wear?

查看:229
本文介绍了如何创建通知是对设备的磨损不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想知道是否有可能为创建两个不同的通知,以及如何? - 一个用于Android设备和其他Android的磨损

Basically, I am wondering if it is possible to create two different notifications and how - one for Android Device and other for Android Wear?

例如:我想刚才 setContentText ,但是在Android设备我想 setContentTitle setContentText

For example: I want to have just setContentText, but on Android device I want setContentTitle and setContentText

目前还没有可能显示通知只是磨损(如 setLocalOnly 只有设备 - 的寻找更多的)。

There is currently no possibility to show notification just on Wear (like setLocalOnly with device only - look for more).

推荐答案

据官方统计是不可能创造磨损和手机两种不同的通知,而无需编写自己的Andr​​oid Wear应用程序扩展。它是唯一可能要定义一个只与 NotificationCompat.Builder.setLocalOnly(真)

Officially it is not possible to create two different notifications for wear and the phone without writing your own Android Wear App extension. It is only possible to define a notification that is only shown on the phone with NotificationCompat.Builder.setLocalOnly(true)

要创建一个只显示在磨损设备的通知,但是你可以(目前)通知添加到组<一href="http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setGroup(java.lang.String)"相对=nofollow> NotificationCompat.Builder.setGroup(randomGroupKey)并省略一组汇总的通知显示。如果通知属于一组不显示它在电话上,因为电话将只显示摘要通知。如果没有总结你得到一个通知只是你的手表。刚生成一个随机组密钥,每看只通知。

To create a Notification that is only shown on a Wear Device however you can (at the moment) add the Notification to a group with NotificationCompat.Builder.setGroup(randomGroupKey) and omit the display of a group summary notification. If a notification belongs to a group it is not displayed on the phone because the phone will only show the summary notification. If there is no summary you get a notification for your watch only. Just generate a random group key for every watch only notification.

正式它只可能创造一个通知,看起来在不同的SmartWatch

Officially it is only possible to create a notification that looks different on a smartwatch.

有关此使用<一个href="https://developer.android.com/reference/android/support/v4/app/NotificationCompat.WearableExtender.html"相对=nofollow> WearableExtender 。例如,这code片断:

For this use a WearableExtender. For example this code snippet:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(getString(R.string.smaple_notification_title));
builder.setSmallIcon(R.drawable.ic_message);
builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ActivateActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));

NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
extender.setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.notif_background));
extender.setContentIcon(R.drawable.ic_message);
extender.setHintHideIcon(true);
extender.extend(builder);

builder.setPriority(NotificationCompat.PRIORITY_LOW);
builder.setContentText(notificationText);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.large_icon));
notificationManager.notify(messageIndex, builder.build());

设定为通知的特殊背景下,隐藏的是在该通知通常显示的应用程序图标,并在屏幕关闭模式的腕表增加了一个新的图标,你通知的preVIEW。

Sets a special background for the notification, hides the app icon that is normally displayed on the notification, and adds a new icon to the preview of your Notification in the "screen off" mode of the watch.

这篇关于如何创建通知是对设备的磨损不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆