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