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-03-24 01:02:25 +01:00
|
|
|
private static NotificationChannel defaultChannel;
|
|
|
|
|
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
|
|
|
|
|
|
|
public static String getDefaultChannelId(NotificationManager manager) {
|
|
|
|
|
|
|
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
|
|
if (defaultChannel == null) {
|
|
|
|
String id = "default";
|
|
|
|
CharSequence name = "KDE Connect";
|
|
|
|
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
|
|
|
defaultChannel = new NotificationChannel(id, name, importance);
|
|
|
|
manager.createNotificationChannel(defaultChannel);
|
|
|
|
}
|
|
|
|
return defaultChannel.getId();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-12-05 23:42:58 +01:00
|
|
|
}
|