{"id":2600,"date":"2022-07-07T15:15:29","date_gmt":"2022-07-07T22:15:29","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/surface-duo\/?p=2600"},"modified":"2022-07-07T15:15:29","modified_gmt":"2022-07-07T22:15:29","slug":"glance-bar-notifications","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/surface-duo\/glance-bar-notifications\/","title":{"rendered":"Notifications on the Glance Bar"},"content":{"rendered":"<p>\n  Hello Android developers! \n<\/p>\n<p>\n  This week we are talking about the Surface Duo 2 Glance Bar feature. If you are wondering what the Glance Bar feature is and how anyone can benefit from it, let\u2019s dive into it together to learn more.\n<\/p>\n<h2>What is the Glance Bar Feature?<\/h2>\n<p>\n  The Glance Bar feature displays notifications of BUCKET_PEOPLE category over the hinge part of the device when it is closed. This feature helps us quickly view notifications, the time, or see whenever someone calls u, without unfolding or unlocking the device.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"1528\" height=\"643\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-1.png\" class=\"wp-image-2601\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-1.png 1528w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-1-300x126.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-1-1024x431.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-1-768x323.png 768w\" sizes=\"(max-width: 1528px) 100vw, 1528px\" \/>\n<\/p>\n<h2>How can I enable the Glance Bar?<\/h2>\n<p>\n  This feature is enabled by default for new devices, but if you want to enable or disable it, you can just go to<strong> Settings<\/strong> &gt; <strong>Surface Duo features<\/strong> &gt; <strong>Glance Bar<\/strong> &gt; <strong>On\/Off<\/strong>. You can also enable or disable specific functionality, including calls, messages, battery level, or volume:\n<\/p>\n<p>\n  <a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/glance-bar-settings-800.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/glance-bar-settings-800.png\" alt=\"Surface Duo 2 showing glance bar settings\" width=\"800\" height=\"632\" class=\"alignnone size-full wp-image-2618\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/glance-bar-settings-800.png 800w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/glance-bar-settings-800-300x237.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/glance-bar-settings-800-768x607.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a>\n<\/p>\n<h2>Glance Bar features<\/h2>\n<p>Here is a list of different notification types that appear on the Glance Bar.<\/p>\n<h3>Incoming calls<\/h3>\n<p>\n  When we receive a call, an animation with blue color will appear.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"986\" height=\"740\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-3.png\" class=\"wp-image-2603\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-3.png 986w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-3-300x225.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-3-768x576.png 768w\" sizes=\"(max-width: 986px) 100vw, 986px\" \/>\n<\/p>\n<h3>Messages<\/h3>\n<p>\n  When we have unread notification messages and we press the power button, a list of all notifications will be displayed. The max number of notification charms from different apps is 4. The notifications will come with an icon and a background color from the application we received the message from; for example, the Skype application is blue. The priority of the notifications is the same as for the status bar.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"986\" height=\"740\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-4.png\" class=\"wp-image-2604\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-4.png 986w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-4-300x225.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-4-768x576.png 768w\" sizes=\"(max-width: 986px) 100vw, 986px\" \/>\n<\/p>\n<h3>Battery<\/h3>\n<p>\n  When we plug in the device to charge, or disconnect the device from a charging cable, an animation will appear with the percentage of the battery level. If it is below 15%, the background color will be red; otherwise, it will be green.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"986\" height=\"740\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-5.png\" class=\"wp-image-2605\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-5.png 986w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-5-300x225.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-5-768x576.png 768w\" sizes=\"(max-width: 986px) 100vw, 986px\" \/>\n<\/p>\n<h3>Volume<\/h3>\n<p>\n  When we press the volume buttons up\/down, an animation will be displayed with the current volume level and a white background color.\n<\/p>\n<h3>Clock<\/h3>\n<p>\n  If you do not have any notifications, you can instantly view the time without folding or opening the device.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"620\" height=\"372\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-6.png\" class=\"wp-image-2606\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-6.png 620w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-6-300x180.png 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/>\n<\/p>\n<h2>Developers, now comes the fun part! How can you see your own notification on Glance Bar?<\/h2>\n<p>\n  First, you need a Surface Duo device but if you do not have a device, no problem. We got you! \n<\/p>\n<p>\n  You can use the <i>Surface Duo Emulator<\/i> to test Glance Bar notifications. Follow the <a href=\"https:\/\/docs.microsoft.com\/dual-screen\/android\/emulator\/\">Surface Duo emulator installation instructions<\/a> for your system (Windows, macOS, and Linux are supported).<\/p>\n<p>\n  Once the emulator is set-up, you need an application to send test notifications. We will make use of the <i>People<\/i> sample from Google: \n<\/p>\n<p><a href=\"https:\/\/github.com\/android\/user-interface-samples\/tree\/main\/People\">https:\/\/github.com\/android\/user-interface-samples\/tree\/main\/People<\/a>\n<\/p>\n<p>\nThe People sample lists a group of animals with whom you can &#8220;chat&#8221; and generate notifications:<\/p>\n<p>\n  <img decoding=\"async\" width=\"971\" height=\"612\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-9.png\" class=\"wp-image-2609\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-9.png 971w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-9-300x189.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-9-768x484.png 768w\" sizes=\"(max-width: 971px) 100vw, 971px\" \/>\n<\/p>\n<p>\n  Using the Surface Duo emulator we can now &#8220;chat&#8221; with our Cat:\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"969\" height=\"618\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-10.png\" class=\"wp-image-2610\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-10.png 969w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-10-300x191.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-10-768x490.png 768w\" sizes=\"(max-width: 969px) 100vw, 969px\" \/>\n<\/p>\n<p>\nAfter we send the message and move the application in background, we need to simulate the closed posture of the device. This animation shows how to do this using the posture control tab:<\/p>\n<p>\n  <img decoding=\"async\" width=\"1435\" height=\"530\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-11.gif\" class=\"wp-image-2611\" \/>\n<\/p>\n<p>\n   The steps shown in the animation are:\n<\/p>\n<ol>\n<li>Go down to the right side of the emulator and click on the 3 dots \u201c&#8230;\u201d \n<li>Navigate to <b>Virtual Sensors<\/b> section\n<li>Click on the <b>Closed<\/b> posture icon \n<li>Wait for the notification to appear in the center of the emulator screen, which mimics the Glance Bar area on a Surface Duo device\n<\/ol>\n<p>If you do not have enough time to move the application in background and receive the message, just go to <strong>ChatRepository.kt<\/strong> class on line 114:\n<\/p>\n<pre>Thread.sleep(5000L)<\/pre>\n<p>\n  and change the value of <code>5000L<\/code> to a bigger number.\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"1031\" height=\"657\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-12.png\" class=\"wp-image-2612\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-12.png 1031w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-12-300x191.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-12-1024x653.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-12-768x489.png 768w\" sizes=\"(max-width: 1031px) 100vw, 1031px\" \/>\n<\/p>\n<p>\n  If you&#8217;re following these steps on your system, you may not have seen the notification on the Glance Bar? Did we forget something? \n<\/p>\n<p>\n  The reason the notifications did not appear on the Glance Bar is because the sample application does not have any color set for the notification. If we do not set any color to the notification builder, by default it would be <code>TRANSPARENT<\/code>. Here\u2019s how to change that: Go to <code>NotificationHelper#showNotification()<\/code> and add this code line to the Notification Compact builder:\n<\/p>\n<pre>.setColor(Color.RED)<\/pre>\n<p>\n  Now let us try one more time \ud83d\ude0a\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"1028\" height=\"687\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-13.png\" class=\"wp-image-2613\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-13.png 1028w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-13-300x200.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-13-1024x684.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-13-768x513.png 768w\" sizes=\"(max-width: 1028px) 100vw, 1028px\" \/>\n<\/p>\n<p>\n  Yeah!, now we know how to display our notifications on the Glance Bar! If we want to change our icon as well as the color, we can call <code>setSmallIcon()<\/code> and add\/replace the current icon:\n<\/p>\n<pre>.setSmallIcon(R.drawable.ic_star)<\/pre>\n<p>\n  Here\u2019s a zoomed-in screenshot of the notification with updated icon:\n<\/p>\n<p>\n  <img decoding=\"async\" width=\"101\" height=\"178\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2022\/07\/word-image-2600-14.png\" class=\"wp-image-2614\" \/>\n<\/p>\n<p>\n  That wraps up what the Glance Bar does and how your apps can take advantage of it using regular Android APIs. \n<\/p>\n<h2>Resources and feedback<\/h2>\n<p>\n  If you have any questions or would like to tell us about your dual-screen applications, use the <a href=\"https:\/\/techcommunity.microsoft.com\/t5\/surface-duo-sdk\/bd-p\/SurfaceDuoSDK\">feedback forum<\/a> or message us on Twitter <a href=\"https:\/\/twitter.com\/surfaceduodev\">@surfaceduodev<\/a>. \n<\/p>\n<p>\n  Finally, please join us every Friday on <a href=\"https:\/\/twitch.tv\/surfaceduodev\">Twitch<\/a> at 11am Pacific time to chat about Surface Duo developer topics!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Android developers! This week we are talking about the Surface Duo 2 Glance Bar feature. If you are wondering what the Glance Bar feature is and how anyone can benefit from it, let\u2019s dive into it together to learn more. What is the Glance Bar Feature? The Glance Bar feature displays notifications of BUCKET_PEOPLE [&hellip;]<\/p>\n","protected":false},"author":95422,"featured_media":2604,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[726,725,46],"class_list":["post-2600","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-surface-duo-sdk","tag-glance-bar","tag-notifications","tag-surface-duo"],"acf":[],"blog_post_summary":"<p>Hello Android developers! This week we are talking about the Surface Duo 2 Glance Bar feature. If you are wondering what the Glance Bar feature is and how anyone can benefit from it, let\u2019s dive into it together to learn more. What is the Glance Bar Feature? The Glance Bar feature displays notifications of BUCKET_PEOPLE [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/2600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/users\/95422"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/comments?post=2600"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/2600\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media\/2604"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media?parent=2600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/categories?post=2600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/tags?post=2600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}