我没有得到它设法显示我基于ElizaChat示例做的背景,但我没有得到它总是黑色的背景.
这是我的代码:
public static void createNotification(Context context) {
int notificationId = 1;
NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText("I am a big style message");
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context)
//.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("hallo")
.setContentText("I am a message")
.setLargeIcon(BitmapFactory.decodeResource(
context.getResources(), R.drawable.clock_bg))
//.setStyle(bigStyle)
;
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
Notification notification =
new WearableNotifications.Builder(notificationBuilder)
.setHintHideIcon(true)
.setMinPriority() // show only on clock
.build();
// Build the notification and issues it with notification manager.
notificationManager.notify(notificationId, notification);
}
Run Code Online (Sandbox Code Playgroud)
任何的想法?
这是我的输出:

正确的方法是在这个简短的示例中使用WearableExtender类似的方法:
NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();
Bitmap bg = BitmapFactory.decodeResource(context.getResources(), background);
extender.setBackground(bg);
notificationBuilder.extend(extender);
Run Code Online (Sandbox Code Playgroud)
原始答案 /替代方案
我找到了一个需要使用 BigPictureStyle 的解决方案,如下所示:
Bitmap background = BitmapFactory.decodeResource(context.getResources(),
R.drawable.clock_bg);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(context)
.setContentTitle("hallo")
.setContentText("I am a message")
.setLargeIcon(background)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(background));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1452 次 |
| 最近记录: |