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