diff options
Diffstat (limited to 'docs/html/wear/notifications')
| -rw-r--r-- | docs/html/wear/notifications/creating.html | 722 | ||||
| -rw-r--r-- | docs/html/wear/notifications/pages.html | 500 | ||||
| -rw-r--r-- | docs/html/wear/notifications/remote-input.html | 648 | ||||
| -rw-r--r-- | docs/html/wear/notifications/stacks.html | 507 |
4 files changed, 2377 insertions, 0 deletions
diff --git a/docs/html/wear/notifications/creating.html b/docs/html/wear/notifications/creating.html new file mode 100644 index 0000000..e83b57a --- /dev/null +++ b/docs/html/wear/notifications/creating.html @@ -0,0 +1,722 @@ +<!DOCTYPE html> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<html> +<head> + + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="viewport" content="width=device-width" /> + +<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" /> +<title>Creating Notifications for Android Wear | Android Developers</title> + +<!-- STYLESHEETS --> +<link rel="stylesheet" +href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold" title="roboto"> +<link href="/assets/css/default.css" rel="stylesheet" type="text/css"> + + + +<!-- JAVASCRIPT --> +<script src="//www.google.com/jsapi" type="text/javascript"></script> +<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script> +<script type="text/javascript"> + var toRoot = "/"; + var metaTags = []; + var devsite = false; +</script> +<script src="/assets/js/docs.js" type="text/javascript"></script> + +<script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-5831155-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); +</script> +</head> + +<body class="gc-documentation + " itemscope itemtype="http://schema.org/Article"> + + + +<a name="top"></a> + + <!-- Header --> + <div id="header"> + <div class="wrap" id="header-wrap"> + <div class="col-3 logo-wear"> + <a href="/wear/index.html"> + <img src="/wear/images/android-wear.png" height="16" alt="Android Wear" /> + </a> + </div> + + + <div class="col-8" style="margin:0"><h1 style="margin:1px 0 0 20px;padding:0;line-height:16px; + color:#666;font-weight:100;font-size:24px;">Developer Preview</h1></div> + + + <!-- New Search --> + <div class="menu-container"> + <div class="moremenu"> + <div id="more-btn"></div> + </div> + <div class="morehover" id="moremenu"> + <div class="top"></div> + <div class="mid"> + <div class="header">Links</div> + <ul> + <li><a href="https://play.google.com/apps/publish/">Google Play Developer Console</a></li> + <li><a href="http://android-developers.blogspot.com/">Android Developers Blog</a></li> + <li><a href="/about/index.html">About Android</a></li> + </ul> + <div class="header">Android Sites</div> + <ul> + <li><a href="http://www.android.com">Android.com</a></li> + <li class="active"><a>Android Developers</a></li> + <li><a href="http://source.android.com">Android Open Source Project</a></li> + </ul> + + + + <div class="header">Language</div> + <div id="language" class="locales"> + <select name="language" onChange="changeLangPref(this.value, true)"> + <option value="en">English</option> + <option value="es">Español</option> + <option value="ja">日本語</option> + <option value="ko">한국어</option> + <option value="ru">Русский</option> + <option value="zh-cn">中文 (中国)</option> + <option value="zh-tw">中文 (台灣)</option> + </select> + </div> + <script type="text/javascript"> + <!-- + loadLangPref(); + //--> + </script> + + + + + <br class="clearfix" /> + </div><!-- end mid --> + <div class="bottom"></div> + </div><!-- end morehover --> + + <div class="search" id="search-container"> + <div class="search-inner"> + <div id="search-btn"></div> + <div class="left"></div> + <form onsubmit="return submit_search()"> + <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q" +onfocus="search_focus_changed(this, true)" onblur="search_focus_changed(this, false)" +onkeydown="return search_changed(event, true, '/')" +onkeyup="return search_changed(event, false, '/')" /> + </form> + <div class="right"></div> + <a class="close hide">close</a> + <div class="left"></div> + <div class="right"></div> + </div> + </div><!-- end search --> + + <div class="search_filtered_wrapper reference"> + <div class="suggest-card reference no-display"> + <ul class="search_filtered"> + </ul> + </div> + </div> + + <div class="search_filtered_wrapper docs"> + <div class="suggest-card dummy no-display"> </div> + <div class="suggest-card develop no-display"> + <ul class="search_filtered"> + </ul> + <div class="child-card guides no-display"> + </div> + <div class="child-card training no-display"> + </div> + <div class="child-card samples no-display"> + </div> + </div> + <div class="suggest-card design no-display"> + <ul class="search_filtered"> + </ul> + </div> + <div class="suggest-card distribute no-display"> + <ul class="search_filtered"> + </ul> + </div> + </div><!-- end search_filtered_wrapper --> + + </div> + <!-- end menu_container --> + + + </div><!-- end header-wrap --> + </div> + <!-- /Header --> + + + <div id="searchResults" class="wrap" style="display:none;"> + <h2 id="searchTitle">Results</h2> + <div id="leftSearchControl" class="search-control">Loading...</div> + </div> + + + + + + <div class="wrap clearfix" id="body-content"> + <div class="col-4" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement"> + <div id="devdoc-nav" class="scroll-pane"> +<a class="totop" href="#top" data-g-event="left-nav-top">to top</a> + +<ul id="nav"> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/preview/start.html">Get Started + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/design/user-interface.html">UI Overview + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/design/index.html">Design Principles + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/creating.html">Creating Notifications for Android Wear + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/remote-input.html">Receiving Voice Input from a Notification + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/pages.html">Adding Pages to a Notification + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/stacks.html">Stacking Notifications + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header"><a href="/reference/android/preview/support/package-summary.html">Notification Reference</a></div> + <ul class="tree-list-children"> +<li class="nav-section"> +<div class="nav-section-header-ref"><span class="tree-list-subtitle package" title="android.preview.support.v4.app">android.preview.support.v4.app</span></div> + <ul> +<li><a href="/reference/android/preview/support/v4/app/NotificationManagerCompat.html">NotificationManagerCompat</a></li> + </ul> +</li> + +<li class="nav-section"> +<div class="nav-section-header-ref"><span class="tree-list-subtitle package" title="android.preview.support.wearable.notifications">android.preview.support.wearable.notifications</span></div> +<ul> + +<li><a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html">RemoteInput</a></li> +<li><a href="/reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html" >RemoteInput.Builder</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.html">WearableNotifications</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html">WearableNotifications.Action</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.Builder.html">WearableNotifications.Action.Builder</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html">WearableNotifications.Builder</a></li> + </ul> + </li> +</ul> +</li> + + + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/license.html">License Agreement</a></div> + </li> + + +</ul> + + + + </div> + </div> <!-- end side-nav --> + <script> + $(document).ready(function() { + scrollIntoView("devdoc-nav"); + }); + </script> + + + + +<div class="col-12" id="doc-col" > + + + + + + <h1 itemprop="name" >Creating Notifications for Android Wear</h1> + + + + + + + <div id="jd-content"> + + + <div class="jd-descr" itemprop="articleBody"> + <p>When an Android device such as a phone or tablet is connected to an Android wearable, +all notifications are shared between the devices by default. On the Android wearable, each +notification appears as a new card in the <a href="/wear/design/user-interface.html#Stream" +>context stream</a>.</p> + +<img src="/wear/images/notification_phone@2x.png" width="700" height="265" /> + + +<p>So without any effort, your app notifications are available to users on Android Wear. +However, you can enhance the user experience in several ways. For instance, +if users may respond to a notification by entering text, such as to reply to +a message, you can add the ability for users to reply by voice directly from the +wearable.</p> + +<p>To help you provide the best user experience +for your notifications on Android Wear, this guide shows you how to +build notifications using standard templates in +the <code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html">NotificationCompat.Builder</a></code> APIs, plus how to begin +extending your notification's capabilities for the wearable user experience.</p> + +<p class="note"><strong>Note:</strong> +Notifications using <code><a href="/reference/android/widget/RemoteViews.html">RemoteViews</a></code> are stripped of custom +layouts and the system uses only the text and icons in the +<code><a href="/reference/android/app/Notification.html">Notification</a></code> object to +display the notification in a card. However, custom card layouts will be supported by +the official Android Wear SDK that is coming later.</p> +</div> + + + + +<h2 id="Import">Import the Necessary Classes</h2> + +<p>To begin development, you must first complete the instructions in the <a +href="/wear/preview/start">Get Started with the Developer Preview</a> document. +As mentioned in that document, your app must include +both the <a href="http://developer.android.com/tools/support-library/features.html#v4">v4 support +library</a> and the Developer Preview support library. So to get started, +you should include the following imports in your project code:</p> + +<pre> +import android.preview.support.wearable.notifications.*; +import android.preview.support.v4.app.NotificationManagerCompat; +import android.support.v4.app.NotificationCompat; +</pre> + +<p class="caution"><strong>Caution:</strong> +The APIs in the current Android Wear Developer Preview are intended for <b>development and testing purposes only</b>, not for production apps. Google may change this Developer Preview significantly prior to the official release of the Android Wear SDK. You may not publicly distribute or ship any application using this Developer Preview, as this Developer Preview will no longer be supported after the official SDK is released (which will cause applications based only on the Developer Preview to break).</p> + + + +<h2 id="NotificationBuilder">Create Notifications with the Notification Builder</h2> + +<p>The <a href="http://developer.android.com/tools/support-library/features.html#v4">v4 +support library</a> allows you to create notifications using the latest notification features +such as action buttons and large icons, while remaining compatible with Android 1.6 (API level +4) and higher.</p> + + +<p>For example, here's some code that creates and issues a notification using the +<code><a href="/reference/android/support/v4/app/NotificationCompat.html">NotificationCompat</a></code> APIs combined with the new +<a href="/reference/android/preview/support/v4/app/NotificationManagerCompat.html"> +<code>NotificationManagerCompat</code></a> API:</p> + + +<pre> +int notificationId = 001; +// Build intent for notification content +Intent viewIntent = new Intent(this, ViewEventActivity.class); +viewIntent.putExtra(EXTRA_EVENT_ID, eventId); +PendingIntent viewPendingIntent = + PendingIntent.getActivity(this, 0, viewIntent, 0); + +NotificationCompat.Builder notificationBuilder = + new NotificationCompat.Builder(this) + .setSmallIcon(R.drawable.ic_event) + .setContentTitle(eventTitle) + .setContentText(eventLocation) + .setContentIntent(viewPendingIntent); + +// Get an instance of the NotificationManager service +NotificationManagerCompat notificationManager = + NotificationManagerCompat.from(this); + +// Build the notification and issues it with notification manager. +notificationManager.notify(notificationId, notificationBuilder.build()); +</pre> + +<p>When this notification appears on a handheld device, the user can invoke the +<code><a href="/reference/android/app/PendingIntent.html">PendingIntent</a></code> +specified by the <code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentIntent(android.app.PendingIntent)">setContentIntent()</a></code> method by touching the notification. When this +notification appears on an Android wearable, the user can swipe the notification to the left to +reveal the <strong>Open</strong> action, which invokes the intent on the handheld device.</p> + + + + + + +<img src="/wear/images/circle_email_action.png" height="200" style="float:right;clear:right;margin:0 0 20px 60px" /> + +<h2 id="ActionButtons">Add Action Buttons</h2> + +<p>In addition to the primary content action defined by +<code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentIntent(android.app.PendingIntent)">setContentIntent()</a></code>, you can add other actions by passing a <code><a href="/reference/android/app/PendingIntent.html">PendingIntent</a></code> to +the <code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html#addAction(int, java.lang.CharSequence, android.app.PendingIntent)">addAction()</a></code> method.</p> + +<p>For example, the following code shows the same type of notification from above, but adds an +action to view the event location on a map.</p> + +<pre style="clear:right"> +// Build an intent for an action to view a map +Intent mapIntent = new Intent(Intent.ACTION_VIEW); +Uri geoUri = Uri.parse("geo:0,0?q=" + Uri.encode(location)); +mapIntent.setData(geoUri); +PendingIntent mapPendingIntent = + PendingIntent.getActivity(this, 0, mapIntent, 0); + +NotificationCompat.Builder notificationBuilder = + new NotificationCompat.Builder(this) + .setSmallIcon(R.drawable.ic_event) + .setContentTitle(eventTitle) + .setContentText(eventLocation) + .setContentIntent(viewPendingIntent) + <b>.addAction(R.drawable.ic_map, + getString(R.string.map), mapPendingIntent);</b> +</pre> + +<p>On a handheld device, the action appears as an +additional button attached to the notification. On an Android wearable, the action appears as +a large button when the user swipes the notification to the left. When the user taps the action, +the associated <code><a href="/reference/android/content/Intent.html">Intent</a></code> is invoked on the handheld device.</p> + +<p class="note"><strong>Tip:</strong> If your notifications includes a "Reply" action + (such as for a messaging app), you can enhance the behavior by enabling + voice input replies directly from the Android wearable. For more information, read + <a href="/wear/notifications/remote-input.html">Receiving Voice Input from a Notification</a>. +</p> + +<p>For details about designing action buttons (including the icon specifications), see the +<a href="/wear/design/index.html#NotifictionActions">Design Principles of Android +Wear</a>.</p> + + +<h2 id="BigView">Add a Big View</h2> + +<img src="/wear/images/06_images.png" height="200" style="float:right;margin:0 0 20px 40px" /> + +<p>You can insert extended text content +to your notification by adding one of the "big view" styles to your notification. On a +handheld device, users can see the big view content by expanding the notification, +while on Android Wear, the big view content is visible by default.</p> + +<p>To add the extended content to your notification, call <code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html#setStyle(android.support.v4.app.NotificationCompat.Style)">setStyle()</a></code> on the <code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html">NotificationCompat.Builder</a></code> object, passing it an instance of either +<code><a href="/reference/android/support/v4/app/NotificationCompat.BigTextStyle.html">BigTextStyle</a></code> or +<code><a href="/reference/android/support/v4/app/NotificationCompat.InboxStyle.html">InboxStyle</a></code>.</p> + +<p>For example, the following code adds an instance of +<code><a href="/reference/android/support/v4/app/NotificationCompat.BigTextStyle.html">NotificationCompat.BigTextStyle</a></code> to the event notification, +in order to include the complete event description (which includes more text than can fit +into the space provided for <code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentText(java.lang.CharSequence)">setContentText()</a></code>).</p> + + +<pre style="clear:right"> +// Specify the 'big view' content to display the long +// event description that may not fit the normal content text. +BigTextStyle bigStyle = new NotificationCompat.BigTextStyle(); +bigStyle.bigText(eventDescription); + +NotificationCompat.Builder notificationBuilder = + new NotificationCompat.Builder(this) + .setSmallIcon(R.drawable.ic_event) + .setLargeIcon(BitmapFractory.decodeResource( + getResources(), R.drawable.notif_background)) + .setContentTitle(eventTitle) + .setContentText(eventLocation) + .setContentIntent(viewPendingIntent) + .addAction(R.drawable.ic_map, + getString(R.string.map), mapPendingIntent) + <b>.setStyle(bigStyle);</b> +</pre> + +<p>Notice that you can add a large background image to any notification using the +<code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html#setLargeIcon(android.graphics.Bitmap)">setLargeIcon()</a></code> +method. For more information about designing notifications with large images, see the +<a href="/wear/design/index.html#Images">Design Principles of Android +Wear</a>.</p> + + + +<h2 id="NewFeatures">Add New Features for Wearables</h2> + +<p>The Android Wear preview support library provides new APIs that + allow you to enhance the user experience for notifications on a wearable device. For example, + you can add additional pages of content that users can view by swiping to the left, or add the ability +for users to deliver your app a text response using voice input.</p> + +<p>To use these new APIs, pass your instance of +<code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html">NotificationCompat.Builder</a></code> to the + <a href="/reference/android/preview/support/notifications/WearableNotifications.html"> <code>WearableNotifications.Builder()</code></a> constructor. You can then add new +features to your notification using the + <a href="/wear/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html" + ><code>WearableNotifications.Builder</code></a> methods. For example:</p> + +<pre> +// Create a NotificationCompat.Builder for standard notification features +NotificationCompat.Builder notificationBuilder = + new NotificationCompat.Builder(mContext) + .setContentTitle("New mail from " + sender.toString()) + .setContentText(subject) + .setSmallIcon(R.drawable.new_mail); + +// Create a WearablesNotification.Builder to add special functionality for wearables +Notification notification = + new WearableNotifications.Builder(notificationBuilder) + .setHintHideIcon(true) + .build(); +</pre> + +<p>The <a href="/reference/android/preview/support/notifications/WearableNotifications.Builder.html#setBigActionIcon(int)"> + <code>setHintHideIcon()</code></a> method removes your app icon from the notification card. + This method is just one example of new notification features available from the + <a href="/wear/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html" + ><code>WearableNotifications.Builder</code></a> class.</p> + +<p>When you want to deliver your notifications, be certain to always use the + <a href="/reference/android/preview/support/v4/app/NotificationManagerCompat.html"> + <code>NotificationManagerCompat</code></a> API:</p> + +<pre> +// Get an instance of the NotificationManager service +NotificationManagerCompat notificationManager = + NotificationManagerCompat.from(this); + +// Build the notification and issues it with notification manager. +notificationManager.notify(notificationId, notification); +</pre> + +<p>If you instead use the framework's <code><a href="/reference/android/app/NotificationManager.html">NotificationManager</a></code>, some +features from <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html"><code>WearableNotifications.Builder</code></a> +will not work.</p> + +<p>To continue enhancing your notifications for wearables using + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder" + ><code>WearableNotifications.Builder</code></a> and other APIs in the + preview support library, see the following developer guides:</p> + + <dl> + <dt><a href="/wear/notifications/remote-input.html">Receiving Voice Input +from a Notification</a></dt> + <dd>Add an action that receives voice input from the user and delivers the +transcribed message to your app.</dd> + <dt><a href="/wear/notifications/pages.html">Adding Pages to a Notification</a></dt> + <dd>Add additional pages of information that are visible when the user +swipes to the left.</dd> + <dt><a href="/wear/notifications/stacks.html">Stacking Notifications</a></dt> + <dd>Place all similar notifications from your app in a stack, allowing each to be +viewed individually without adding multiple cards to the card stream.</dd> + </dl> + + +<div class="next-docs"> + +<div class="col-12"> + <h2 class="norule">You might also want to read:</h2> + <dl> + <dt><a href="/training/notify-user/index.html">Notifying the User</a></dt> + <dd>Learn more about how to create notifications.</dd> + <dt><a href="/guide/components/intents-filters.html">Intents and Intent Filters</a></dt> + <dd>Learn everything you need to know about the <code><a href="/reference/android/content/Intent.html">Intent</a></code> +APIs, used by notificaton actions.</dd> + </dl> +</div> +</div> + + +</body> +</html> + + </div> + + <div class="content-footer layout-content-row" + itemscope itemtype="http://schema.org/SiteNavigationElement"> + <div class="layout-content-col col-9" style="padding-top:4px"> + + <div class="g-plusone" data-size="medium"></div> + + </div> + + <div class="paging-links layout-content-col col-4"> + + </div> + + </div> + + + + + </div> <!-- end jd-content --> + +<div id="footer" class="wrap" > + + + <div id="copyright"> + + Except as noted, this content is + licensed under <a href="http://creativecommons.org/licenses/by/2.5/"> + Creative Commons Attribution 2.5</a>. For details and + restrictions, see the <a href="/license.html">Content + License</a>. + </div> + + + <div id="footerlinks"> + + <p> + <a href="/about/index.html">About Android</a> | + <a href="/legal.html">Legal</a> | + <a href="/support.html">Support</a> + </p> + </div> + +</div> <!-- end footer --> +</div><!-- end doc-content --> + +</div> <!-- end body-content --> + + + + + + +<!-- Start of Tag --> +<script type="text/javascript"> +var axel = Math.random() + ""; +var a = axel * 10000000000000; +document.write('<iframe src="https://2507573.fls.doubleclick.net/activityi;src=2507573;type=other026;cat=googl348;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>'); +</script> +<noscript> +<iframe src="https://2507573.fls.doubleclick.net/activityi;src=2507573;type=other026;cat=googl348;ord=1?" width="1" height="1" frameborder="0" style="display:none"></iframe> +</noscript> +<!-- End of Tag --> +</body> +</html> + + + diff --git a/docs/html/wear/notifications/pages.html b/docs/html/wear/notifications/pages.html new file mode 100644 index 0000000..abff8fa --- /dev/null +++ b/docs/html/wear/notifications/pages.html @@ -0,0 +1,500 @@ +<!DOCTYPE html> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<html> +<head> + + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="viewport" content="width=device-width" /> + +<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" /> +<title>Adding Pages to a Notification | Android Developers</title> + +<!-- STYLESHEETS --> +<link rel="stylesheet" +href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold" title="roboto"> +<link href="/assets/css/default.css" rel="stylesheet" type="text/css"> + + + +<!-- JAVASCRIPT --> +<script src="//www.google.com/jsapi" type="text/javascript"></script> +<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script> +<script type="text/javascript"> + var toRoot = "/"; + var metaTags = []; + var devsite = false; +</script> +<script src="/assets/js/docs.js" type="text/javascript"></script> + +<script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-5831155-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); +</script> +</head> + +<body class="gc-documentation + " itemscope itemtype="http://schema.org/Article"> + + + +<a name="top"></a> + + <!-- Header --> + <div id="header"> + <div class="wrap" id="header-wrap"> + <div class="col-3 logo-wear"> + <a href="/wear/index.html"> + <img src="/wear/images/android-wear.png" height="16" alt="Android Wear" /> + </a> + </div> + + + <div class="col-8" style="margin:0"><h1 style="margin:1px 0 0 20px;padding:0;line-height:16px; + color:#666;font-weight:100;font-size:24px;">Developer Preview</h1></div> + + + <!-- New Search --> + <div class="menu-container"> + <div class="moremenu"> + <div id="more-btn"></div> + </div> + <div class="morehover" id="moremenu"> + <div class="top"></div> + <div class="mid"> + <div class="header">Links</div> + <ul> + <li><a href="https://play.google.com/apps/publish/">Google Play Developer Console</a></li> + <li><a href="http://android-developers.blogspot.com/">Android Developers Blog</a></li> + <li><a href="/about/index.html">About Android</a></li> + </ul> + <div class="header">Android Sites</div> + <ul> + <li><a href="http://www.android.com">Android.com</a></li> + <li class="active"><a>Android Developers</a></li> + <li><a href="http://source.android.com">Android Open Source Project</a></li> + </ul> + + + + <div class="header">Language</div> + <div id="language" class="locales"> + <select name="language" onChange="changeLangPref(this.value, true)"> + <option value="en">English</option> + <option value="es">Español</option> + <option value="ja">日本語</option> + <option value="ko">한국어</option> + <option value="ru">Русский</option> + <option value="zh-cn">中文 (中国)</option> + <option value="zh-tw">中文 (台灣)</option> + </select> + </div> + <script type="text/javascript"> + <!-- + loadLangPref(); + //--> + </script> + + + + + <br class="clearfix" /> + </div><!-- end mid --> + <div class="bottom"></div> + </div><!-- end morehover --> + + <div class="search" id="search-container"> + <div class="search-inner"> + <div id="search-btn"></div> + <div class="left"></div> + <form onsubmit="return submit_search()"> + <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q" +onfocus="search_focus_changed(this, true)" onblur="search_focus_changed(this, false)" +onkeydown="return search_changed(event, true, '/')" +onkeyup="return search_changed(event, false, '/')" /> + </form> + <div class="right"></div> + <a class="close hide">close</a> + <div class="left"></div> + <div class="right"></div> + </div> + </div><!-- end search --> + + <div class="search_filtered_wrapper reference"> + <div class="suggest-card reference no-display"> + <ul class="search_filtered"> + </ul> + </div> + </div> + + <div class="search_filtered_wrapper docs"> + <div class="suggest-card dummy no-display"> </div> + <div class="suggest-card develop no-display"> + <ul class="search_filtered"> + </ul> + <div class="child-card guides no-display"> + </div> + <div class="child-card training no-display"> + </div> + <div class="child-card samples no-display"> + </div> + </div> + <div class="suggest-card design no-display"> + <ul class="search_filtered"> + </ul> + </div> + <div class="suggest-card distribute no-display"> + <ul class="search_filtered"> + </ul> + </div> + </div><!-- end search_filtered_wrapper --> + + </div> + <!-- end menu_container --> + + + </div><!-- end header-wrap --> + </div> + <!-- /Header --> + + + <div id="searchResults" class="wrap" style="display:none;"> + <h2 id="searchTitle">Results</h2> + <div id="leftSearchControl" class="search-control">Loading...</div> + </div> + + + + + + <div class="wrap clearfix" id="body-content"> + <div class="col-4" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement"> + <div id="devdoc-nav" class="scroll-pane"> +<a class="totop" href="#top" data-g-event="left-nav-top">to top</a> + +<ul id="nav"> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/preview/start.html">Get Started + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/design/user-interface.html">UI Overview + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/design/index.html">Design Principles + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/creating.html">Creating Notifications for Android Wear + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/remote-input.html">Receiving Voice Input from a Notification + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/pages.html">Adding Pages to a Notification + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/stacks.html">Stacking Notifications + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header"><a href="/reference/android/preview/support/package-summary.html">Notification Reference</a></div> + <ul class="tree-list-children"> +<li class="nav-section"> +<div class="nav-section-header-ref"><span class="tree-list-subtitle package" title="android.preview.support.v4.app">android.preview.support.v4.app</span></div> + <ul> +<li><a href="/reference/android/preview/support/v4/app/NotificationManagerCompat.html">NotificationManagerCompat</a></li> + </ul> +</li> + +<li class="nav-section"> +<div class="nav-section-header-ref"><span class="tree-list-subtitle package" title="android.preview.support.wearable.notifications">android.preview.support.wearable.notifications</span></div> +<ul> + +<li><a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html">RemoteInput</a></li> +<li><a href="/reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html" >RemoteInput.Builder</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.html">WearableNotifications</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html">WearableNotifications.Action</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.Builder.html">WearableNotifications.Action.Builder</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html">WearableNotifications.Builder</a></li> + </ul> + </li> +</ul> +</li> + + + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/license.html">License Agreement</a></div> + </li> + + +</ul> + + + + </div> + </div> <!-- end side-nav --> + <script> + $(document).ready(function() { + scrollIntoView("devdoc-nav"); + }); + </script> + + + + +<div class="col-12" id="doc-col" > + + + + + + <h1 itemprop="name" >Adding Pages to a Notification</h1> + + + + + + + <div id="jd-content"> + + + <div class="jd-descr" itemprop="articleBody"> + <img src="/wear/images/09_pages.png" height="200" style="float:right;margin:0 0 20px 40px" /> +<img src="/wear/images/08_pages.png" height="200" style="float:right;margin:0 0 20px 40px" /> + +<p>When you'd like to provide more information without requiring users +to open your app on their phones, you can +add one or more pages to the notification on Android Wear. The additional pages +appear immediately to the right of the main notification card. +For information about when to use and how to design +multiple pages, see the +<a href="/wear/design/index.html#NotificationPages">Design Principles of Android +Wear</a>.</p> + + +<p>When creating a notification with multiple pages, start by creating the main notification +(the first page) the way you'd like the notification to appear on a phone +or tablet. Then, add pages one at a time with the +<a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addPage(android.app.Notification)"> +<code>addPage()</code></a> method, or add multiple pages in a <code><a href="/reference/java/util/Collection.html">Collection</a></code> with the +<a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addPages(java.util.Collection<android.app.Notification>)"> +<code>addPages()</code></a> method.</p> + + +<p>For example, here's some code that adds a second page to a notification:</p> + +<pre> +// Create builder for the main notification +NotificationCompat.Builder notificationBuilder = + new NotificationCompat.Builder(this) + .setSmallIcon(R.drawable.new_message) + .setContentTitle("Page 1") + .setContentText("Short message") + .setContentIntent(viewPendingIntent); + +// Create a big text style for the second page +BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle(); +secondPageStyle.setBigContentTitle("Page 2") + .bigText("A lot of text..."); + +// Create second page notification +Notification secondPageNotification = + new NotificationCompat.Builder(this) + .setStyle(secondPageStyle) + .build(); + +// Create main notification and add the second page +Notification twoPageNotification = + new WearableNotifications.Builder(notificationBuilder) + .addPage(secondPageNotification) + .build(); +</pre> + + + + +</body> +</html> + + </div> + + <div class="content-footer layout-content-row" + itemscope itemtype="http://schema.org/SiteNavigationElement"> + <div class="layout-content-col col-9" style="padding-top:4px"> + + <div class="g-plusone" data-size="medium"></div> + + </div> + + <div class="paging-links layout-content-col col-4"> + + </div> + + </div> + + + + + </div> <!-- end jd-content --> + +<div id="footer" class="wrap" > + + + <div id="copyright"> + + Except as noted, this content is + licensed under <a href="http://creativecommons.org/licenses/by/2.5/"> + Creative Commons Attribution 2.5</a>. For details and + restrictions, see the <a href="/license.html">Content + License</a>. + </div> + + + <div id="footerlinks"> + + <p> + <a href="/about/index.html">About Android</a> | + <a href="/legal.html">Legal</a> | + <a href="/support.html">Support</a> + </p> + </div> + +</div> <!-- end footer --> +</div><!-- end doc-content --> + +</div> <!-- end body-content --> + + + + + + +<!-- Start of Tag --> +<script type="text/javascript"> +var axel = Math.random() + ""; +var a = axel * 10000000000000; +document.write('<iframe src="https://2507573.fls.doubleclick.net/activityi;src=2507573;type=other026;cat=googl348;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>'); +</script> +<noscript> +<iframe src="https://2507573.fls.doubleclick.net/activityi;src=2507573;type=other026;cat=googl348;ord=1?" width="1" height="1" frameborder="0" style="display:none"></iframe> +</noscript> +<!-- End of Tag --> +</body> +</html> + + + diff --git a/docs/html/wear/notifications/remote-input.html b/docs/html/wear/notifications/remote-input.html new file mode 100644 index 0000000..6500233 --- /dev/null +++ b/docs/html/wear/notifications/remote-input.html @@ -0,0 +1,648 @@ +<!DOCTYPE html> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<html> +<head> + + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="viewport" content="width=device-width" /> + +<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" /> +<title>Receiving Voice Input from a Notification | Android Developers</title> + +<!-- STYLESHEETS --> +<link rel="stylesheet" +href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold" title="roboto"> +<link href="/assets/css/default.css" rel="stylesheet" type="text/css"> + + + +<!-- JAVASCRIPT --> +<script src="//www.google.com/jsapi" type="text/javascript"></script> +<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script> +<script type="text/javascript"> + var toRoot = "/"; + var metaTags = []; + var devsite = false; +</script> +<script src="/assets/js/docs.js" type="text/javascript"></script> + +<script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-5831155-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); +</script> +</head> + +<body class="gc-documentation + " itemscope itemtype="http://schema.org/Article"> + + + +<a name="top"></a> + + <!-- Header --> + <div id="header"> + <div class="wrap" id="header-wrap"> + <div class="col-3 logo-wear"> + <a href="/wear/index.html"> + <img src="/wear/images/android-wear.png" height="16" alt="Android Wear" /> + </a> + </div> + + + <div class="col-8" style="margin:0"><h1 style="margin:1px 0 0 20px;padding:0;line-height:16px; + color:#666;font-weight:100;font-size:24px;">Developer Preview</h1></div> + + + <!-- New Search --> + <div class="menu-container"> + <div class="moremenu"> + <div id="more-btn"></div> + </div> + <div class="morehover" id="moremenu"> + <div class="top"></div> + <div class="mid"> + <div class="header">Links</div> + <ul> + <li><a href="https://play.google.com/apps/publish/">Google Play Developer Console</a></li> + <li><a href="http://android-developers.blogspot.com/">Android Developers Blog</a></li> + <li><a href="/about/index.html">About Android</a></li> + </ul> + <div class="header">Android Sites</div> + <ul> + <li><a href="http://www.android.com">Android.com</a></li> + <li class="active"><a>Android Developers</a></li> + <li><a href="http://source.android.com">Android Open Source Project</a></li> + </ul> + + + + <div class="header">Language</div> + <div id="language" class="locales"> + <select name="language" onChange="changeLangPref(this.value, true)"> + <option value="en">English</option> + <option value="es">Español</option> + <option value="ja">日本語</option> + <option value="ko">한국어</option> + <option value="ru">Русский</option> + <option value="zh-cn">中文 (中国)</option> + <option value="zh-tw">中文 (台灣)</option> + </select> + </div> + <script type="text/javascript"> + <!-- + loadLangPref(); + //--> + </script> + + + + + <br class="clearfix" /> + </div><!-- end mid --> + <div class="bottom"></div> + </div><!-- end morehover --> + + <div class="search" id="search-container"> + <div class="search-inner"> + <div id="search-btn"></div> + <div class="left"></div> + <form onsubmit="return submit_search()"> + <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q" +onfocus="search_focus_changed(this, true)" onblur="search_focus_changed(this, false)" +onkeydown="return search_changed(event, true, '/')" +onkeyup="return search_changed(event, false, '/')" /> + </form> + <div class="right"></div> + <a class="close hide">close</a> + <div class="left"></div> + <div class="right"></div> + </div> + </div><!-- end search --> + + <div class="search_filtered_wrapper reference"> + <div class="suggest-card reference no-display"> + <ul class="search_filtered"> + </ul> + </div> + </div> + + <div class="search_filtered_wrapper docs"> + <div class="suggest-card dummy no-display"> </div> + <div class="suggest-card develop no-display"> + <ul class="search_filtered"> + </ul> + <div class="child-card guides no-display"> + </div> + <div class="child-card training no-display"> + </div> + <div class="child-card samples no-display"> + </div> + </div> + <div class="suggest-card design no-display"> + <ul class="search_filtered"> + </ul> + </div> + <div class="suggest-card distribute no-display"> + <ul class="search_filtered"> + </ul> + </div> + </div><!-- end search_filtered_wrapper --> + + </div> + <!-- end menu_container --> + + + </div><!-- end header-wrap --> + </div> + <!-- /Header --> + + + <div id="searchResults" class="wrap" style="display:none;"> + <h2 id="searchTitle">Results</h2> + <div id="leftSearchControl" class="search-control">Loading...</div> + </div> + + + + + + <div class="wrap clearfix" id="body-content"> + <div class="col-4" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement"> + <div id="devdoc-nav" class="scroll-pane"> +<a class="totop" href="#top" data-g-event="left-nav-top">to top</a> + +<ul id="nav"> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/preview/start.html">Get Started + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/design/user-interface.html">UI Overview + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/design/index.html">Design Principles + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/creating.html">Creating Notifications for Android Wear + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/remote-input.html">Receiving Voice Input from a Notification + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/pages.html">Adding Pages to a Notification + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/stacks.html">Stacking Notifications + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header"><a href="/reference/android/preview/support/package-summary.html">Notification Reference</a></div> + <ul class="tree-list-children"> +<li class="nav-section"> +<div class="nav-section-header-ref"><span class="tree-list-subtitle package" title="android.preview.support.v4.app">android.preview.support.v4.app</span></div> + <ul> +<li><a href="/reference/android/preview/support/v4/app/NotificationManagerCompat.html">NotificationManagerCompat</a></li> + </ul> +</li> + +<li class="nav-section"> +<div class="nav-section-header-ref"><span class="tree-list-subtitle package" title="android.preview.support.wearable.notifications">android.preview.support.wearable.notifications</span></div> +<ul> + +<li><a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html">RemoteInput</a></li> +<li><a href="/reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html" >RemoteInput.Builder</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.html">WearableNotifications</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html">WearableNotifications.Action</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.Builder.html">WearableNotifications.Action.Builder</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html">WearableNotifications.Builder</a></li> + </ul> + </li> +</ul> +</li> + + + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/license.html">License Agreement</a></div> + </li> + + +</ul> + + + + </div> + </div> <!-- end side-nav --> + <script> + $(document).ready(function() { + scrollIntoView("devdoc-nav"); + }); + </script> + + + + +<div class="col-12" id="doc-col" > + + + + + + <h1 itemprop="name" >Receiving Voice Input from a Notification</h1> + + + + + + + <div id="jd-content"> + + + <div class="jd-descr" itemprop="articleBody"> + <img src="/wear/images/13_voicereply.png" height="200" width="169" style="float:right;margin:0 0 20px 60px" /> + +<img src="/wear/images/03_actions.png" height="200" width="169" style="float:right;margin:0 0 20px 40px" /> + +<p>If your notification includes an action to respond with text, + such as to reply to an email, it should normally launch an activity + on the handheld device. However, when your notification appears on an Android Wear device, you can + allow users to dictate a reply with voice input. You can also provide pre-defined text + replies for the user to select.</p> + +<p>When the user replies with voice or selects one of the available +responses, the system delivers your app on the handheld the +message as a string extra in the <code><a href="/reference/android/content/Intent.html">Intent</a></code> you specified +to be used for the action.</p> + + +<h2 id="RemoteInput">Define the Remote Input</h2> + +<p>To create an action that supports voice input, first create an instance of + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html"> +<code>RemoteInput</code></a> using the + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> APIs. + The + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> constructor takes a string that the system + will use as a key for the <code><a href="/reference/android/content/Intent.html">Intent</a></code> extra that caries the reply message + to your app on the handheld.</p> + +<p>For example, here's a new + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html"> +<code>RemoteInput</code></a> object that provides a custom + label for the voice input prompt:</p> + +<pre class="prettyprint"> +// Key for the string that's delivered in the action's intent +private static final String EXTRA_VOICE_REPLY = "extra_voice_reply"; + +String replyLabel = getResources().getString(R.string.reply_label); + +RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) + .setLabel(replyLabel) + .build(); +</pre> + + +<h3>Add Pre-defined Text Responses</h3> + +<img src="/wear/images/12_voicereply.png" height="200" style="float:right;margin:0 0 20px 40px" /> + +<p>In addition to allowing voice input, you can + provide up to five text responses the user can select for quick replies. Call + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html#setChoices(java.lang.String[])"><code>setChoices()</code></a> and pass it a string array.</p> + +<p>For example, you may define some responses in a resource array:</p> + +<p class="code-caption">res/values/strings.xml</code> +<pre class="prettyprint"> +<?xml version="1.0" encoding="utf-8"?> +<resources> + <string-array name="reply_choices"> + <item>Yes</item> + <item>No</item> + <item>Maybe</item> + </string-array> +</resources> +</pre> + +<p>Then, inflate the string array and add it to the + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a>:</p> + +<pre> +String replyLabel = getResources().getString(R.string.reply_label); +String[] replyChoices = getResources().getStringArray(R.array.reply_choices); + +RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) + .setLabel(replyLabel) + .setChoices(replyChoices) + .build(); +</pre> + + + + +<h2 id="PrimaryAction">Receive Voice Input for the Primary Action</h2> + +<p>If "Reply" is your notification's primary action (defined by the <code><a href="/reference/android/support/v4/app/NotificationCompat.Builder.html#setContentIntent(android.app.PendingIntent)">setContentIntent()</a></code> +method), then you should attach the + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to the main action using + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addRemoteInputForContentIntent(android.preview.support.wearable.notifications.RemoteInput)"> +<code>addRemoteInputForContentIntent()</code></a>. For example:</p> + +<pre> +// Create intent for reply action +Intent replyIntent = new Intent(this, ReplyService.class); +PendingIntent replyPendingIntent = + PendingIntent.getService(this, 0, replyIntent, 0); + +// Build the notification +NotificationCompat.Builder replyNotificationBuilder = + new NotificationCompat.Builder(this) + .setSmallIcon(R.drawable.ic_new_message) + .setContentTitle("Message from Travis") + .setContentText("I love key lime pie!") + .setContentIntent(replyPendingIntent); + +// Create the remote input +RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) + .setLabel(replyLabel) + .build(); + +// Create wearable notification and add remote input +Notification replyNotification = + new WearableNotifications.Builder(replyNotificationBuilder) + .addRemoteInputForContentIntent(replyAction) + .build(); +</pre> + + +<p>By using + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addRemoteInputForContentIntent(android.preview.support.wearable.notifications.RemoteInput)"> +<code>addRemoteInputForContentIntent()</code></a> to add the + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> object to the notification's primary action, +the button that normally appears as an "Open" action becomes the "Reply" action +and starts the voice input UI when users select it on Android Wear.</p> + + + +<h2 id="NewAction">Receive Voice Input for a Secondary Action</h2> + +<p>If the "Reply" action is not your notification's primary action and you want to enable +voice input for a secondary action, add the + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to a new action button defined by an + <a href="/reference/android/preview/support/wearable/notifications/Action.html"> +<code>Action</code></a> object.</p> + +<p>You should instantiate the + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> +<code>Action</code></a> with the + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.Builder.html"><code>Action.Builder()</code></a> +constructor, which takes an icon and text label for the action button, plus the +<code><a href="/reference/android/app/PendingIntent.html">PendingIntent</a></code> +the system should use to invoke your app when the user selects the action. For example:</p> + +<pre> +// Create the pending intent to fire when the user selects the action +Intent replyIntent = new Intent(this, ReplyActivity.class); +PendingIntent pendingReplyIntent = + PendingIntent.getActivity(this, 0, replyIntent, 0); + +// Create the remote input +RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY) + .setLabel(replyLabel) + .build(); + +// Create the notification action +Action replyAction = new Action.Builder(R.drawable.ic_message, + "Reply", pendingIntent) + .addRemoteInput(remoteInput) + .build(); +</pre> + + +<p>After you add the + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html"><code>RemoteInput</code></a> to the + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> +<code>Action</code></a>, add the + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html"> +<code>Action</code></a> to the + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html"><code>WearableNotifications.Builder</code></a> using + <a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#addAction(Action)"><code>addAction()</code></a>. +For example:</p> + +<pre> +// Create basic notification builder +NotificationCompat.Builder replyNotificationBuilder = + new NotificationCompat.Builder(this) + .setContentTitle("New message"); + +// Create the notification action and add remote input +Action replyAction = new Action.Builder(R.drawable.ic_message, + "Reply", pendingIntent) + .addRemoteInput(remoteInput) + .build(); + +// Create wearable notification and add action +Notification replyNotification = + new WearableNotifications.Builder(replyNotificationBuilder) + .addAction(replyAction) + .build(); +</pre> + +<p>Now, when the user selects "Reply" from an Android wearable, + the system prompts for voice input (and provides the list of pre-defined replies, if provided). + Once the user completes a response, the system invokes + the <code><a href="/reference/android/content/Intent.html">Intent</a></code> attached to the action and adds the +<code>EXTRA_VOICE_REPLY</code> extra (the string + you passed to the + <a href="/reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html"><code>RemoteInput.Builder</code></a> constructor) + with the user's message as the string value.</p> + + + + +</body> +</html> + + </div> + + <div class="content-footer layout-content-row" + itemscope itemtype="http://schema.org/SiteNavigationElement"> + <div class="layout-content-col col-9" style="padding-top:4px"> + + <div class="g-plusone" data-size="medium"></div> + + </div> + + <div class="paging-links layout-content-col col-4"> + + </div> + + </div> + + + + + </div> <!-- end jd-content --> + +<div id="footer" class="wrap" > + + + <div id="copyright"> + + Except as noted, this content is + licensed under <a href="http://creativecommons.org/licenses/by/2.5/"> + Creative Commons Attribution 2.5</a>. For details and + restrictions, see the <a href="/license.html">Content + License</a>. + </div> + + + <div id="footerlinks"> + + <p> + <a href="/about/index.html">About Android</a> | + <a href="/legal.html">Legal</a> | + <a href="/support.html">Support</a> + </p> + </div> + +</div> <!-- end footer --> +</div><!-- end doc-content --> + +</div> <!-- end body-content --> + + + + + + +<!-- Start of Tag --> +<script type="text/javascript"> +var axel = Math.random() + ""; +var a = axel * 10000000000000; +document.write('<iframe src="https://2507573.fls.doubleclick.net/activityi;src=2507573;type=other026;cat=googl348;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>'); +</script> +<noscript> +<iframe src="https://2507573.fls.doubleclick.net/activityi;src=2507573;type=other026;cat=googl348;ord=1?" width="1" height="1" frameborder="0" style="display:none"></iframe> +</noscript> +<!-- End of Tag --> +</body> +</html> + + + diff --git a/docs/html/wear/notifications/stacks.html b/docs/html/wear/notifications/stacks.html new file mode 100644 index 0000000..5d10165 --- /dev/null +++ b/docs/html/wear/notifications/stacks.html @@ -0,0 +1,507 @@ +<!DOCTYPE html> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<html> +<head> + + +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="viewport" content="width=device-width" /> + +<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" /> +<title>Stacking Notifications | Android Developers</title> + +<!-- STYLESHEETS --> +<link rel="stylesheet" +href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold" title="roboto"> +<link href="/assets/css/default.css" rel="stylesheet" type="text/css"> + + + +<!-- JAVASCRIPT --> +<script src="//www.google.com/jsapi" type="text/javascript"></script> +<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script> +<script type="text/javascript"> + var toRoot = "/"; + var metaTags = []; + var devsite = false; +</script> +<script src="/assets/js/docs.js" type="text/javascript"></script> + +<script type="text/javascript"> + var _gaq = _gaq || []; + _gaq.push(['_setAccount', 'UA-5831155-1']); + _gaq.push(['_trackPageview']); + + (function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); +</script> +</head> + +<body class="gc-documentation + " itemscope itemtype="http://schema.org/Article"> + + + +<a name="top"></a> + + <!-- Header --> + <div id="header"> + <div class="wrap" id="header-wrap"> + <div class="col-3 logo-wear"> + <a href="/wear/index.html"> + <img src="/wear/images/android-wear.png" height="16" alt="Android Wear" /> + </a> + </div> + + + <div class="col-8" style="margin:0"><h1 style="margin:1px 0 0 20px;padding:0;line-height:16px; + color:#666;font-weight:100;font-size:24px;">Developer Preview</h1></div> + + + <!-- New Search --> + <div class="menu-container"> + <div class="moremenu"> + <div id="more-btn"></div> + </div> + <div class="morehover" id="moremenu"> + <div class="top"></div> + <div class="mid"> + <div class="header">Links</div> + <ul> + <li><a href="https://play.google.com/apps/publish/">Google Play Developer Console</a></li> + <li><a href="http://android-developers.blogspot.com/">Android Developers Blog</a></li> + <li><a href="/about/index.html">About Android</a></li> + </ul> + <div class="header">Android Sites</div> + <ul> + <li><a href="http://www.android.com">Android.com</a></li> + <li class="active"><a>Android Developers</a></li> + <li><a href="http://source.android.com">Android Open Source Project</a></li> + </ul> + + + + <div class="header">Language</div> + <div id="language" class="locales"> + <select name="language" onChange="changeLangPref(this.value, true)"> + <option value="en">English</option> + <option value="es">Español</option> + <option value="ja">日本語</option> + <option value="ko">한국어</option> + <option value="ru">Русский</option> + <option value="zh-cn">中文 (中国)</option> + <option value="zh-tw">中文 (台灣)</option> + </select> + </div> + <script type="text/javascript"> + <!-- + loadLangPref(); + //--> + </script> + + + + + <br class="clearfix" /> + </div><!-- end mid --> + <div class="bottom"></div> + </div><!-- end morehover --> + + <div class="search" id="search-container"> + <div class="search-inner"> + <div id="search-btn"></div> + <div class="left"></div> + <form onsubmit="return submit_search()"> + <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q" +onfocus="search_focus_changed(this, true)" onblur="search_focus_changed(this, false)" +onkeydown="return search_changed(event, true, '/')" +onkeyup="return search_changed(event, false, '/')" /> + </form> + <div class="right"></div> + <a class="close hide">close</a> + <div class="left"></div> + <div class="right"></div> + </div> + </div><!-- end search --> + + <div class="search_filtered_wrapper reference"> + <div class="suggest-card reference no-display"> + <ul class="search_filtered"> + </ul> + </div> + </div> + + <div class="search_filtered_wrapper docs"> + <div class="suggest-card dummy no-display"> </div> + <div class="suggest-card develop no-display"> + <ul class="search_filtered"> + </ul> + <div class="child-card guides no-display"> + </div> + <div class="child-card training no-display"> + </div> + <div class="child-card samples no-display"> + </div> + </div> + <div class="suggest-card design no-display"> + <ul class="search_filtered"> + </ul> + </div> + <div class="suggest-card distribute no-display"> + <ul class="search_filtered"> + </ul> + </div> + </div><!-- end search_filtered_wrapper --> + + </div> + <!-- end menu_container --> + + + </div><!-- end header-wrap --> + </div> + <!-- /Header --> + + + <div id="searchResults" class="wrap" style="display:none;"> + <h2 id="searchTitle">Results</h2> + <div id="leftSearchControl" class="search-control">Loading...</div> + </div> + + + + + + <div class="wrap clearfix" id="body-content"> + <div class="col-4" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement"> + <div id="devdoc-nav" class="scroll-pane"> +<a class="totop" href="#top" data-g-event="left-nav-top">to top</a> + +<ul id="nav"> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/preview/start.html">Get Started + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/design/user-interface.html">UI Overview + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/design/index.html">Design Principles + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/creating.html">Creating Notifications for Android Wear + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/remote-input.html">Receiving Voice Input from a Notification + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/pages.html">Adding Pages to a Notification + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/notifications/stacks.html">Stacking Notifications + </a></div> + </li> + + <li class="nav-section"> + <div class="nav-section-header"><a href="/reference/android/preview/support/package-summary.html">Notification Reference</a></div> + <ul class="tree-list-children"> +<li class="nav-section"> +<div class="nav-section-header-ref"><span class="tree-list-subtitle package" title="android.preview.support.v4.app">android.preview.support.v4.app</span></div> + <ul> +<li><a href="/reference/android/preview/support/v4/app/NotificationManagerCompat.html">NotificationManagerCompat</a></li> + </ul> +</li> + +<li class="nav-section"> +<div class="nav-section-header-ref"><span class="tree-list-subtitle package" title="android.preview.support.wearable.notifications">android.preview.support.wearable.notifications</span></div> +<ul> + +<li><a href="/reference/android/preview/support/wearable/notifications/RemoteInput.html">RemoteInput</a></li> +<li><a href="/reference/android/preview/support/wearable/notifications/RemoteInput.Builder.html" >RemoteInput.Builder</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.html">WearableNotifications</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.html">WearableNotifications.Action</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Action.Builder.html">WearableNotifications.Action.Builder</a></li> + +<li><a href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html">WearableNotifications.Builder</a></li> + </ul> + </li> +</ul> +</li> + + + + <li class="nav-section"> + <div class="nav-section-header empty"><a href="/wear/license.html">License Agreement</a></div> + </li> + + +</ul> + + + + </div> + </div> <!-- end side-nav --> + <script> + $(document).ready(function() { + scrollIntoView("devdoc-nav"); + }); + </script> + + + + +<div class="col-12" id="doc-col" > + + + + + + <h1 itemprop="name" >Stacking Notifications</h1> + + + + + + + <div id="jd-content"> + + + <div class="jd-descr" itemprop="articleBody"> + <img src="/wear/images/11_bundles_B.png" height="200" width="169" style="float:right;margin:0 0 20px 40px" /> +<img src="/wear/images/11_bundles_A.png" height="200" width="169" style="float:right;margin:0 0 20px 40px" /> + +<p>When your app creates more than one notification about the same type, you should traditionally +update the existing notification with a summary of all the notifications instead of creating multiple notifications. For instance, instead +of three notifications for each received email, you should create one with a summary such as "3 new +messages." To view the contents of each message, the user must then touch the notification to open +your app.</p> + +<p>However, when a user is viewing your notifications on a wearable device, you can create +a stack that collects all the notifications for immediate access without creating multiple +cards in the card stream.</p> + +<p>For details about designing notification stacks, see the +<a href="/wear/design/index.html#NotificationStacks">Design Principles of Android +Wear</a>.</p> + + +<h2 id="AddGroup">Add Each Notification to a Group</h2> + +<p>To create a stack, call <a +href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#setGroup(java.lang.String, int)"> +<code>setGroup()</code></a> for each notification you want in the stack, passing the same +group key. For example:</p> + +<pre style="clear:right"> +final static String GROUP_KEY_EMAILS = "group_key_emails"; + +NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext) + .setContentTitle("New mail from " + sender) + .setContentText(subject) + .setSmallIcon(R.drawable.new_mail); + +Notification notif = new WearableNotifications.Builder(builder) + .setGroup(GROUP_KEY_EMAILS) + .build(); +</pre> + +<p>By default, notifications appear in the order in which you added them, with the most recent + notification visible at the top. You can define a specific position in the group + by passing an order position as the second parameter for <a +href="/reference/android/preview/support/wearable/notifications/WearableNotifications.Builder.html#setGroup(java.lang.String, int)"> +<code>setGroup()</code></a>.</p> + + +<h2 id="AddSummary">Add a Summary Notification</h2> + +<p>It's important that you still provide a summary notification for handheld devices. So in +addition to adding each unique notification to the same stack group, also add the summary +notification but set its order position to be <a +href="/reference/android/preview/support/wearable/notifications/WearableNotifications.html#GROUP_ORDER_SUMMARY"><code>GROUP_ORDER_SUMMARY</code></a>. +The notification in this position does not appear in the stack on the wearable but +appears as the only notification on the handheld.</p> + +<pre> +Notification summaryNotification = new WearableNotifications.Builder(builder) + .setGroup(GROUP_KEY_EMAILS, WearableNotifications.GROUP_ORDER_SUMMARY) + .build(); +</pre> + + +</body> +</html> + + </div> + + <div class="content-footer layout-content-row" + itemscope itemtype="http://schema.org/SiteNavigationElement"> + <div class="layout-content-col col-9" style="padding-top:4px"> + + <div class="g-plusone" data-size="medium"></div> + + </div> + + <div class="paging-links layout-content-col col-4"> + + </div> + + </div> + + + + + </div> <!-- end jd-content --> + +<div id="footer" class="wrap" > + + + <div id="copyright"> + + Except as noted, this content is + licensed under <a href="http://creativecommons.org/licenses/by/2.5/"> + Creative Commons Attribution 2.5</a>. For details and + restrictions, see the <a href="/license.html">Content + License</a>. + </div> + + + <div id="footerlinks"> + + <p> + <a href="/about/index.html">About Android</a> | + <a href="/legal.html">Legal</a> | + <a href="/support.html">Support</a> + </p> + </div> + +</div> <!-- end footer --> +</div><!-- end doc-content --> + +</div> <!-- end body-content --> + + + + + + +<!-- Start of Tag --> +<script type="text/javascript"> +var axel = Math.random() + ""; +var a = axel * 10000000000000; +document.write('<iframe src="https://2507573.fls.doubleclick.net/activityi;src=2507573;type=other026;cat=googl348;ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>'); +</script> +<noscript> +<iframe src="https://2507573.fls.doubleclick.net/activityi;src=2507573;type=other026;cat=googl348;ord=1?" width="1" height="1" frameborder="0" style="display:none"></iframe> +</noscript> +<!-- End of Tag --> +</body> +</html> + + + |
