Android NotificationChannels Sample (Kotlin)
===================================
Demonstration of using channels to categorize notifications by topic. This feature was
added in Android O, and allows users to have fine-grained control over their
notification preferences.
Introduction
------------
Android O introduces notification channels to provide a unified system to help users
manage notifications. When you target Android O, you must implement one or more
notification channels to display notifications to your users.
You can create a notification channel for each distinct type of notification you need
to send. You can also create notification channels to reflect choices made by users of
your app. For example, you might setup separate notification channels for each
conversation group created by a user in a messaging app.
To create a channel, call `[NotificationManager.createNotificationChannels()][1]`. You
can then use `[Notification.Builder.setChannel()][2]` to assign your notification to that
channel.
Users can now manage most of the settings associated with notifications using a
consistent system UI. All notifications posted to a notification channel behave the
same. To access the settings screen, use the `ACTION_CHANNEL_NOTIFICATION_SETTINGS`
intent:
```
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
startActivity(intent);
```
[1]: https://developer.android.com/reference/android/app/NotificationManager.html#createNotificationChannels(java.util.List<android.app.NotificationChannel>)
[2]: https://android-dot-devsite.googleplex.com/reference/android/app/Notification.Builder.html#setChannel(java.lang.String)
Pre-requisites
--------------
- Android SDK Preview O
- Android Build Tools v25.0.3
- Android Support Repository
Screenshots
-------------
<img src="screenshots/1-main.png" height="400" alt="Screenshot"/>
Getting Started
---------------
This sample uses the Gradle build system. To build this project, use the
"gradlew build" command or use "Import Project" in Android Studio.
Support
-------
- Google+ Community: https://plus.google.com/communities/105153134372062985968
- Stack Overflow: http://stackoverflow.com/questions/tagged/android
If you've found an error in this sample, please file an issue:
https://github.com/googlesamples/android-NotificationChannels
Patches are encouraged, and may be submitted by forking this project and
submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
License
-------
Copyright 2017 The Android Open Source Project, Inc.
Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for
additional information regarding copyright ownership. The ASF licenses this
file to you under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
没有合适的资源?快使用搜索试试~ 我知道了~
android 8.0 notification 写法
共70个文件
xml:28个
png:16个
gradle:6个
需积分: 16 11 下载量 43 浏览量
2018-07-26
11:29:11
上传
评论
收藏 1.92MB ZIP 举报
温馨提示
android 8.0 对 通知栏有了很大的改变,以往的方法写通知栏会报错,google新加了一个notificationChannel,而且必须添加,这里是Demo。
资源推荐
资源详情
资源评论
收起资源包目录
android-NotificationChannels-master.zip (70个子文件)
android-NotificationChannels-master
gradle
wrapper
gradle-wrapper.jar 49KB
gradle-wrapper.properties 230B
README.md 3KB
build.gradle 12B
.google
packaging.yaml 642B
gradlew.bat 2KB
gradlew 5KB
LICENSE 11KB
screenshots
1-main.png 857KB
icon-web.png 34KB
CONTRIBUTING.md 2KB
Application
build.gradle 1KB
src
main
AndroidManifest.xml 1KB
java
com
example
android
notificationchannels
NotificationHelper.java 4KB
MainActivity.java 6KB
res
values
base-strings.xml 1KB
template-styles.xml 1KB
colors.xml 208B
strings.xml 1KB
template-dimens.xml 1KB
dimens.xml 211B
mipmap-xxhdpi
ic_launcher.png 6KB
layout
activity_main.xml 4KB
mipmap-xhdpi
ic_launcher.png 4KB
drawable-hdpi
tile.9.png 196B
mipmap-hdpi
ic_launcher.png 3KB
values-v11
template-styles.xml 726B
values-sw600dp
template-styles.xml 876B
template-dimens.xml 802B
mipmap-mdpi
ic_launcher.png 2KB
values-v21
base-colors.xml 658B
base-template-styles.xml 768B
values-w820dp
dimens.xml 358B
mipmap-xxxhdpi
ic_launcher.png 9KB
kotlinApp
gradle
wrapper
gradle-wrapper.jar 49KB
gradle-wrapper.properties 230B
README.md 3KB
build.gradle 0B
.google
packaging.yaml 643B
gradlew.bat 2KB
gradlew 5KB
LICENSE 32KB
screenshots
1-main.png 857KB
icon-web.png 34KB
CONTRIBUTING.md 2KB
Application
build.gradle 2KB
src
main
AndroidManifest.xml 1KB
java
com
example
android
notificationchannels
MainActivity.kt 5KB
NotificationHelper.kt 4KB
res
values
base-strings.xml 1KB
template-styles.xml 1KB
colors.xml 208B
strings.xml 1KB
template-dimens.xml 1KB
dimens.xml 211B
mipmap-xxhdpi
ic_launcher.png 6KB
layout
activity_main.xml 4KB
mipmap-xhdpi
ic_launcher.png 4KB
drawable-hdpi
tile.9.png 196B
mipmap-hdpi
ic_launcher.png 3KB
values-v11
template-styles.xml 726B
values-sw600dp
template-styles.xml 876B
template-dimens.xml 802B
mipmap-mdpi
ic_launcher.png 2KB
values-v21
base-colors.xml 658B
base-template-styles.xml 768B
values-w820dp
dimens.xml 358B
mipmap-xxxhdpi
ic_launcher.png 9KB
settings.gradle 23B
settings.gradle 23B
共 70 条
- 1
资源评论
Lesen_c
- 粉丝: 1
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功