2016-12-05 23:42:58 +01:00
|
|
|
package org.kde.kdeconnect.Helpers;
|
|
|
|
|
|
|
|
import android.app.Notification;
|
2018-03-24 01:02:25 +01:00
|
|
|
import android.app.NotificationChannel;
|
2016-12-05 23:42:58 +01:00
|
|
|
import android.app.NotificationManager;
|
|
|
|
|
|
|
|
public class NotificationHelper {
|
|
|
|
|
2018-05-15 00:32:51 +02:00
|
|
|
public static class Channels {
|
|
|
|
public final static String PERSISTENT = "persistent";
|
|
|
|
public final static String DEFAULT = "default";
|
|
|
|
}
|
2018-03-24 01:02:25 +01:00
|
|
|
|
2016-12-05 23:42:58 +01:00
|
|
|
public static void notifyCompat(NotificationManager notificationManager, int notificationId, Notification notification) {
|
|
|
|
try {
|
|
|
|
notificationManager.notify(notificationId, notification);
|
2018-03-03 16:06:52 +01:00
|
|
|
} 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);
|
2018-03-03 16:06:52 +01:00
|
|
|
} 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!/
|
|
|
|
}
|
|
|
|
}
|
2018-03-24 01:02:25 +01:00
|
|
|
|
2018-05-15 00:32:51 +02:00
|
|
|
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);
|
2018-03-24 01:02:25 +01:00
|
|
|
}
|
2018-05-15 00:32:51 +02:00
|
|
|
|
2018-03-24 01:02:25 +01:00
|
|
|
}
|
|
|
|
|
2016-12-05 23:42:58 +01:00
|
|
|
}
|