我已经为Android Wear设备创建了一个项目。我需要在可穿戴设备上自定义通知样式。有什么办法吗?
我的方法是
Intent displayIntent = new Intent(getApplicationContext(), CustomNotification.class);
PendingIntent displayPendingIntent = PendingIntent.getActivity(getApplicationContext(),
0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification =
new NotificationCompat.Builder(context)
.extend(new WearableExtender()
.setDisplayIntent(displayPendingIntent))
.build();
int notificationId = 001;
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(this);
notificationManager.notify(notificationId , notification);
但是我没有收到通知。
是否可以使用自定义布局设计进行自定义?
这是清单部分
<activity android:name="com.client.android.CustomNotification"
android:exported="true"
android:allowEmbedded="true"
android:taskAffinity=""
android:theme="@android:style/Theme.DeviceDefault.Light" />
请查看有关在Android Wear上创建自定义通知的官方文档。
您可以将样式应用到notificaitons,例如BigPictureStyle
,BigTextStyle
或InboxStyle
。
这是使用示例BigTextStyle
:
// Specify the 'big view' content to display the long
// event description that may not fit the normal content text.
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText(eventDescription);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_event)
.setLargeIcon(BitmapFractory.decodeResource(getResources(), R.drawable.notif_background))
.setContentTitle(eventTitle)
.setContentText(eventLocation)
.setContentIntent(viewPendingIntent)
.addAction(R.drawable.ic_map, getString(R.string.map), mapPendingIntent)
.setStyle(bigStyle);
更多信息:http :
//developer.android.com/training/wearables/notifications/creating.html#BigView
您可以在自己的布局中创建一个布局Activity
并将其嵌入到通知中:https : //developer.android.com/training/wearables/apps/layouts.html#CustomNotifications
注意:请注意,此方法有一些限制,仅适用于通知是直接通过Android Wear设备(而不是手机)提交的。
还请阅读该教程末尾的注释:
注意:在主屏幕上查看通知时,系统会使用从通知的语义数据生成的标准模板来显示该通知。该模板可在所有表面上正常使用。当用户向上滑动通知时,他们将看到通知的自定义活动。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句