android - 没有卡片背景无法将页面添加到 Android Wear 通知

标签 android wear-os

Android Wear 很可能不支持此功能,但似乎应该有一些解决方法。我想向通知添加自定义第二页,但我不希望它具有白色卡片背景。

以下是我创建通知的方式:

Intent secondPageIntent = new Intent(this, SecondPageActivity.class);
PendingIntent secondPagePendingIntent = PendingIntent.getActivity(this, 0, secondPageIntent, 0);


Notification secondPageNotification = new NotificationCompat.Builder(this)
                        .extend(new NotificationCompat.WearableExtender()
                                        .setDisplayIntent(secondPagePendingIntent)
                                        .setHintShowBackgroundOnly(true)
                        )
                        .build();

Intent firstPageIntent = new Intent(this, FirstPageActivity.class);
PendingIntent firstPagePendingIntent = PendingIntent.getActivity(this, 0, firstPageIntent, PendingIntent.FLAG_UPDATE_CURRENT);


NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .extend(new NotificationCompat.WearableExtender()
                                        .setDisplayIntent(firstPagePendingIntent)
                                        .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.background))
                                        .addPage(secondPageNotification)
                        );


NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
                notificationManager.notify(curNotificationId++, builder.build());

我试过:

  1. 设置不执行任何操作的 setHintShowBackgroundOnly
  2. 从 SecondPageActivity 中,尝试获取 parentActivity 并将其 alpha 设置为 0。不起作用,parentActivity 为空。
  3. 调用 setCustomContentHeight(0) 不会移除卡片,它只会变瘦
  4. 我尝试不使用第二个页面,而是在用户滑动时启动一个 Activity ,但它看起来不太好

我真的不知道接下来要尝试什么。我是一位经验丰富的工程师,但对 Android 还很陌生。任何想法或建议都会有所帮助。

谢谢!

最佳答案

如果你想去掉你必须设置的白卡

setCustomSizePreset(WearableExtender.SIZE_FULL_SCREEN)


所以不是这样的:
custom content with card decoration

您的自定义内容将出现在整个屏幕上(没有卡片装饰)。 custom content without card decoration

请注意,自定义 Activity 的背景由 list 中声明的​​样式定义。不幸的是,任何具有透明背景的主题都不起作用,因此背景需要不透明:(

此处作为问题提交:https://code.google.com/p/android/issues/detail?id=73900
我真的希望他们将来允许透明背景:\

关于android - 没有卡片背景无法将页面添加到 Android Wear 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25374269/

相关文章:

java - Android ListView 与 SimpleCursorAdapter - CursorIndexOutOfBoundsException 错误

java - 无法通过蓝牙进行调试

安卓磨损 : how to store image data into watch

android - 将实时开发人员通知发送到 Tomcat 机器以进行应用内购买

android - 使用默认来电屏幕调用假电话

android - 安装应用程序时如何使用应用程序链接将参数传递给要检索的android playstore

android - 有什么方法可以检测时钟是否是圆的?

Android wearableListenerService 从 Activity 调用方法

android - 从 Android 可穿戴模拟器接收语音输入

android - 解析具有属性的 xml