README.md
1
2Android NotificationChannels Sample
3===================================
4
5Demonstration of using channels to categorize notifications by topic. This feature was
6 added in Android O, and allows users to have fine-grained control over their
7 notification preferences.
8
9Introduction
10------------
11
12Android O introduces notification channels to provide a unified system to help users
13manage notifications. When you target Android O, you must implement one or more
14notification channels to display notifications to your users.
15
16You can create a notification channel for each distinct type of notification you need
17to send. You can also create notification channels to reflect choices made by users of
18your app. For example, you might setup separate notification channels for each
19conversation group created by a user in a messaging app.
20
21To create a channel, call `[NotificationManager.createNotificationChannels()][1]`. You
22can then use `[Notification.Builder.setChannel()][2]` to assign your notification to that
23channel.
24
25Users can now manage most of the settings associated with notifications using a
26consistent system UI. All notifications posted to a notification channel behave the
27same. To access the settings screen, use the `ACTION_CHANNEL_NOTIFICATION_SETTINGS`
28intent:
29
30```
31Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
32intent.putExtra(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
33intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
34startActivity(intent);
35```
36
37
38[1]: https://developer.android.com/reference/android/app/NotificationManager.html#createNotificationChannels(java.util.List<android.app.NotificationChannel>)
39[2]: https://android-dot-devsite.googleplex.com/reference/android/app/Notification.Builder.html#setChannel(java.lang.String)
40
41Pre-requisites
42--------------
43
44- Android SDK 27
45- Android Build Tools v27.0.2
46- Android Support Repository
47
48Screenshots
49-------------
50
51<img src="screenshots/1-main.png" height="400" alt="Screenshot"/>
52
53Getting Started
54---------------
55
56This sample uses the Gradle build system. To build this project, use the
57"gradlew build" command or use "Import Project" in Android Studio.
58
59Support
60-------
61
62- Google+ Community: https://plus.google.com/communities/105153134372062985968
63- Stack Overflow: http://stackoverflow.com/questions/tagged/android
64
65If you've found an error in this sample, please file an issue:
66https://github.com/googlesamples/android-NotificationChannels
67
68Patches are encouraged, and may be submitted by forking this project and
69submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
70
71License
72-------
73
74Copyright 2017 The Android Open Source Project, Inc.
75
76Licensed to the Apache Software Foundation (ASF) under one or more contributor
77license agreements. See the NOTICE file distributed with this work for
78additional information regarding copyright ownership. The ASF licenses this
79file to you under the Apache License, Version 2.0 (the "License"); you may not
80use this file except in compliance with the License. You may obtain a copy of
81the License at
82
83http://www.apache.org/licenses/LICENSE-2.0
84
85Unless required by applicable law or agreed to in writing, software
86distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
87WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
88License for the specific language governing permissions and limitations under
89the License.
90