简体   繁体   中英

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.

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)

You are most likely missing the icon, you need to specify the icon for Android to show your notification. 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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