简体   繁体   English

如何显示来自Android Wear表盘的通知

[英]How to show notification from Android wear watchface

I am trying to show a notification from my Watch face, as I want to show additional information when the user first opens the watchface. 我试图显示来自我的表盘的通知,因为我想在用户首次打开表盘时显示其他信息。

This is similar to the GMT watch face that is installed with the LG G Watch R, that asks the user to swipe left to select the timezone. 这类似于LG G Watch R附带的GMT表盘,要求用户向左滑动以选择时区。

This code does not seem to work for me: 此代码似乎不适用于我:

  Notification.Builder builder = new Notification.Builder(context)
                .setContentTitle("Title")
                .setContentText("Content");

        ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                .notify(1, builder.build());

This was copied from one of Android wear's examples (was not used in a watchface example, just a regular wear app) 这是从Android Wear的示例之一复制而来的(没有在表盘示例中使用,只是常规的Wear应用)

You are most likely missing the icon, you need to specify the icon for Android to show your notification. 您很可能会丢失该图标,您需要为Android指定图标以显示您的通知。 Try specifying everything that the example from the docs mentions: 尝试指定文档示例中提到的所有内容:

Notification noti = new Notification.Builder(mContext)
         .setContentTitle("New mail from " + sender.toString())
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_mail)
         .setLargeIcon(aBitmap)
         .build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM