2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-10-15 14:07:58 +00:00
Files
kdeconnect-android/src/org/kde/kdeconnect/Helpers/NotificationHelper.java

54 lines
2.0 KiB
Java
Raw Normal View History

2016-12-05 23:42:58 +01:00
package org.kde.kdeconnect.Helpers;
import android.app.Notification;
import android.app.NotificationChannel;
2016-12-05 23:42:58 +01:00
import android.app.NotificationManager;
public class NotificationHelper {
public static class Channels {
public final static String PERSISTENT = "persistent";
public final static String DEFAULT = "default";
}
2016-12-05 23:42:58 +01:00
public static void notifyCompat(NotificationManager notificationManager, int notificationId, Notification notification) {
try {
notificationManager.notify(notificationId, notification);
} catch (Exception e) {
2016-12-05 23:42:58 +01:00
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
}
}
public static void notifyCompat(NotificationManager notificationManager, String tag, int notificationId, Notification notification) {
try {
notificationManager.notify(tag, notificationId, notification);
} catch (Exception e) {
2016-12-05 23:42:58 +01:00
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
}
}
public static void initializeChannels(NotificationManager manager) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
return;
}
{
NotificationChannel channel = new NotificationChannel(Channels.DEFAULT, "Other notifications", NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("Rest of KDE Connect notifications");
manager.createNotificationChannel(channel);
}
{
NotificationChannel channel = new NotificationChannel(Channels.PERSISTENT, "Persistent indicator", NotificationManager.IMPORTANCE_MIN);
channel.setDescription("Always present running indicator");
manager.createNotificationChannel(channel);
}
}
2016-12-05 23:42:58 +01:00
}