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