135 lines
6.0 KiB
XML
135 lines
6.0 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!--
|
|
Copyright 2013 The Android Open Source Project
|
|
|
|
Licensed 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.
|
|
-->
|
|
|
|
<sample>
|
|
<name>NotificationChannels</name>
|
|
<group>Notification</group> <!-- This field will be deprecated in the future
|
|
and replaced with the "categories" tags below. -->
|
|
<package>com.example.android.notificationchannels</package>
|
|
|
|
<!-- change minSdk if needed-->
|
|
<minSdk>21</minSdk>
|
|
|
|
<!-- Include additional dependencies here.-->
|
|
<!-- dependency>com.google.android.gms:play-services:5.0.+</dependency -->
|
|
|
|
<strings>
|
|
<intro>
|
|
<![CDATA[
|
|
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 notificatin preferences.
|
|
]]>
|
|
</intro>
|
|
</strings>
|
|
|
|
<!-- The basic templates have already been enabled. Uncomment more as desired. -->
|
|
<template src="base" />
|
|
|
|
<!-- Include common code modules by uncommenting them below. -->
|
|
|
|
<metadata>
|
|
<!-- Values: {DRAFT | PUBLISHED | INTERNAL | DEPRECATED | SUPERCEDED} -->
|
|
<status>PUBLISHED</status>
|
|
<!-- See http://go/sample-categories for details on the next 4 fields. -->
|
|
<!-- Most samples just need to udpate the Categories field. This is a comma-
|
|
seperated list of topic tags. Unlike the old category system, samples
|
|
may have multiple categories, so feel free to add extras. Try to avoid
|
|
simply tagging everything with "UI". :)-->
|
|
<categories>Notification, Android O Preview</categories>
|
|
<technologies>Android</technologies>
|
|
<languages>Java</languages>
|
|
<solutions>Mobile</solutions>
|
|
<!-- Values: {BEGINNER | INTERMEDIATE | ADVANCED | EXPERT} -->
|
|
<!-- Beginner is for "getting started" type content, or essential content.
|
|
(e.g. "Hello World", activities, intents)
|
|
|
|
Intermediate is for content that covers material a beginner doesn't need
|
|
to know, but that a skilled developer is expected to know.
|
|
(e.g. services, basic styles and theming, sync adapters)
|
|
|
|
Advanced is for highly technical content geared towards experienced developers.
|
|
(e.g. performance optimizations, custom views, bluetooth)
|
|
|
|
Expert is reserved for highly technical or specialized content, and should
|
|
be used sparingly. (e.g. VPN clients, SELinux, custom instrumentation runners) -->
|
|
<level>INTERMEDIATE</level>
|
|
<!-- Dimensions: 512x512, PNG fomrat -->
|
|
<icon>screenshots/icon-web.png</icon>
|
|
<!-- Path to screenshots. Use <img> tags for each. -->
|
|
<screenshots>
|
|
<img>screenshots/1-main.png</img>
|
|
</screenshots>
|
|
<!-- List of APIs that this sample should be cross-referenced under. Use <android>
|
|
for fully-qualified Framework class names ("android:" namespace).
|
|
|
|
Use <ext> for custom namespaces, if needed. See "Samples Index API" documentation
|
|
for more details. -->
|
|
<api_refs>
|
|
<android>android.app.NotificationChannel</android>
|
|
<android>android.app.NotificationManager</android>
|
|
<android>android.app.Notification</android>
|
|
<android>android.app.Notification.Builder</android>
|
|
</api_refs>
|
|
|
|
<!-- 1-3 line description of the sample here.
|
|
|
|
Avoid simply rearranging the sample's title. What does this sample actually
|
|
accomplish, and how does it do it? -->
|
|
<description>
|
|
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.
|
|
</description>
|
|
|
|
<!-- Multi-paragraph introduction to sample, from an educational point-of-view.
|
|
Makrdown formatting allowed. This will be used to generate a mini-article for the
|
|
sample on DAC. -->
|
|
<intro>
|
|
<![CDATA[
|
|
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)
|
|
]]>
|
|
</intro>
|
|
</metadata>
|
|
</sample>
|