1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.contacts.util; 18 19 import android.annotation.TargetApi; 20 import android.app.NotificationChannel; 21 import android.app.NotificationManager; 22 import android.content.Context; 23 import android.os.Build; 24 import androidx.core.os.BuildCompat; 25 26 import com.android.contacts.R; 27 28 @TargetApi(Build.VERSION_CODES.O) 29 public class ContactsNotificationChannelsUtil { 30 public static String DEFAULT_CHANNEL = "DEFAULT_CHANNEL"; 31 ContactsNotificationChannelsUtil()32 private ContactsNotificationChannelsUtil() {} 33 createDefaultChannel(Context context)34 public static void createDefaultChannel(Context context) { 35 if (!BuildCompat.isAtLeastO()) { 36 return; 37 } 38 final NotificationManager nm = context.getSystemService(NotificationManager.class); 39 final NotificationChannel channel = new NotificationChannel(DEFAULT_CHANNEL, 40 context.getString(R.string.contacts_default_notification_channel), 41 NotificationManager.IMPORTANCE_LOW); 42 nm.createNotificationChannel(channel); 43 } 44 } 45