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