Download File
Download Project
Settings
Line Wrap
Themes
default
ambiance
bespin
dracula
eclipse
material
mbo
mdn-like
neat
solarized dark
ttcn
zenburn
NotificationUtil.java
/* * Copyright (C) 2017 Google Inc. All Rights Reserved. * * 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. */ package com.example.android.wearable.wear.common.util; import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.os.Build; import com.example.android.wearable.wear.common.mock.MockDatabase; /** * Simplifies common {@link Notification} tasks. */ public class NotificationUtil { public static String createNotificationChannel( Context context, MockDatabase.MockNotificationData mockNotificationData) { // NotificationChannels are required for Notifications on O (API 26) and above. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // The id of the channel. String channelId = mockNotificationData.getChannelId(); // The user-visible name of the channel. CharSequence channelName = mockNotificationData.getChannelName(); // The user-visible description of the channel. String channelDescription = mockNotificationData.getChannelDescription(); int channelImportance = mockNotificationData.getChannelImportance(); boolean channelEnableVibrate = mockNotificationData.isChannelEnableVibrate(); int channelLockscreenVisibility = mockNotificationData.getChannelLockscreenVisibility(); // Initializes NotificationChannel. NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, channelImportance); notificationChannel.setDescription(channelDescription); notificationChannel.enableVibration(channelEnableVibrate); notificationChannel.setLockscreenVisibility(channelLockscreenVisibility); // Adds NotificationChannel to system. Attempting to create an existing notification // channel with its original values performs no operation, so it's safe to perform the // below sequence. NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(notificationChannel); return channelId; } else { // Returns null for pre-O (26) devices. return null; } } }