• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 Copyright 2013 The Android Open Source Project
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16-->
17
18<sample>
19    <name>NotificationChannels</name>
20    <group>Notification</group>  <!-- This field will be deprecated in the future
21                            and replaced with the "categories" tags below. -->
22    <package>com.example.android.notificationchannels</package>
23
24    <!-- change minSdk if needed-->
25    <minSdk>21</minSdk>
26
27    <!-- Include additional dependencies here.-->
28    <!-- dependency>com.google.android.gms:play-services:5.0.+</dependency -->
29
30    <strings>
31        <intro>
32            <![CDATA[
33Demonstration of using channels to categorize notifications by topic. This feature was added in
34Android O, and allows users to have fine-grained control over their notificatin preferences.
35            ]]>
36        </intro>
37    </strings>
38
39    <!-- The basic templates have already been enabled. Uncomment more as desired. -->
40    <template src="base" />
41
42    <!-- Include common code modules by uncommenting them below. -->
43
44    <metadata>
45        <!-- Values: {DRAFT | PUBLISHED | INTERNAL | DEPRECATED | SUPERCEDED} -->
46        <status>PUBLISHED</status>
47        <!-- See http://go/sample-categories for details on the next 4 fields. -->
48        <!-- Most samples just need to udpate the Categories field. This is a comma-
49             seperated list of topic tags. Unlike the old category system, samples
50             may have multiple categories, so feel free to add extras. Try to avoid
51             simply tagging everything with "UI". :)-->
52        <categories>Notification, Android O Preview</categories>
53        <technologies>Android</technologies>
54        <languages>Java</languages>
55        <solutions>Mobile</solutions>
56        <!-- Values: {BEGINNER | INTERMEDIATE | ADVANCED | EXPERT} -->
57        <!-- Beginner is for "getting started" type content, or essential content.
58             (e.g. "Hello World", activities, intents)
59
60             Intermediate is for content that covers material a beginner doesn't need
61             to know, but that a skilled developer is expected to know.
62             (e.g. services, basic styles and theming, sync adapters)
63
64             Advanced is for highly technical content geared towards experienced developers.
65             (e.g. performance optimizations, custom views, bluetooth)
66
67             Expert is reserved for highly technical or specialized content, and should
68             be used sparingly. (e.g. VPN clients, SELinux, custom instrumentation runners) -->
69        <level>INTERMEDIATE</level>
70        <!-- Dimensions: 512x512, PNG fomrat -->
71        <icon>screenshots/icon-web.png</icon>
72        <!-- Path to screenshots. Use <img> tags for each. -->
73        <screenshots>
74            <img>screenshots/1-main.png</img>
75        </screenshots>
76        <!-- List of APIs that this sample should be cross-referenced under. Use <android>
77        for fully-qualified Framework class names ("android:" namespace).
78
79        Use <ext> for custom namespaces, if needed. See "Samples Index API" documentation
80        for more details. -->
81        <api_refs>
82            <android>android.app.NotificationChannel</android>
83            <android>android.app.NotificationManager</android>
84            <android>android.app.Notification</android>
85            <android>android.app.Notification.Builder</android>
86        </api_refs>
87
88        <!-- 1-3 line description of the sample here.
89
90            Avoid simply rearranging the sample's title. What does this sample actually
91            accomplish, and how does it do it? -->
92        <description>
93            Demonstration of using channels to categorize notifications by topic. This feature was
94            added in Android O, and allows users to have fine-grained control over their
95            notification preferences.
96        </description>
97
98        <!-- Multi-paragraph introduction to sample, from an educational point-of-view.
99        Makrdown formatting allowed. This will be used to generate a mini-article for the
100        sample on DAC. -->
101        <intro>
102            <![CDATA[
103Android O introduces notification channels to provide a unified system to help users
104manage notifications. When you target Android O, you must implement one or more
105notification channels to display notifications to your users.
106
107You can create a notification channel for each distinct type of notification you need
108to send. You can also create notification channels to reflect choices made by users of
109your app. For example, you might setup separate notification channels for each
110conversation group created by a user in a messaging app.
111
112To create a channel, call `[NotificationManager.createNotificationChannels()][1]`. You
113can then use `[Notification.Builder.setChannel()][2]` to assign your notification to that
114channel.
115
116Users can now manage most of the settings associated with notifications using a
117consistent system UI. All notifications posted to a notification channel behave the
118same. To access the settings screen, use the `ACTION_CHANNEL_NOTIFICATION_SETTINGS`
119intent:
120
121```
122Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
123intent.putExtra(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
124intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
125startActivity(intent);
126```
127
128
129[1]: https://developer.android.com/reference/android/app/NotificationManager.html#createNotificationChannels(java.util.List<android.app.NotificationChannel>)
130[2]: https://android-dot-devsite.googleplex.com/reference/android/app/Notification.Builder.html#setChannel(java.lang.String)
131            ]]>
132        </intro>
133    </metadata>
134</sample>
135