diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -15,9 +15,9 @@ android { buildToolsVersion '26.0.2' - compileSdkVersion 25 + compileSdkVersion 26 defaultConfig { - minSdkVersion 9 + minSdkVersion 14 targetSdkVersion 25 //multiDexEnabled true //testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner" @@ -79,9 +79,9 @@ } } - implementation 'com.android.support:support-v4:25.4.0' - implementation 'com.android.support:appcompat-v7:25.4.0' - implementation 'com.android.support:design:25.4.0' + implementation 'com.android.support:support-v4:26.1.0' + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support:design:26.1.0' implementation 'com.jakewharton:disklrucache:2.0.2' //For caching album art bitmaps implementation 'org.apache.sshd:sshd-core:0.8.0' //0.9 seems to fail on Android 6 and 1.+ requires java.nio.file, which doesn't exist in Android diff --git a/src/org/kde/kdeconnect/Device.java b/src/org/kde/kdeconnect/Device.java --- a/src/org/kde/kdeconnect/Device.java +++ b/src/org/kde/kdeconnect/Device.java @@ -397,7 +397,9 @@ Resources res = getContext().getResources(); - Notification noti = new NotificationCompat.Builder(getContext()) + final NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); + + Notification noti = new NotificationCompat.Builder(getContext(), NotificationHelper.getDefaultChannelId(notificationManager)) .setContentTitle(res.getString(R.string.pairing_request_from, getName())) .setContentText(res.getString(R.string.tap_to_answer)) .setContentIntent(pendingIntent) @@ -409,7 +411,6 @@ .setDefaults(Notification.DEFAULT_ALL) .build(); - final NotificationManager notificationManager = (NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE); NotificationHelper.notifyCompat(notificationManager, notificationId, noti); BackgroundService.addGuiInUseCounter(context); diff --git a/src/org/kde/kdeconnect/Helpers/NotificationHelper.java b/src/org/kde/kdeconnect/Helpers/NotificationHelper.java --- a/src/org/kde/kdeconnect/Helpers/NotificationHelper.java +++ b/src/org/kde/kdeconnect/Helpers/NotificationHelper.java @@ -1,10 +1,13 @@ package org.kde.kdeconnect.Helpers; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; public class NotificationHelper { + private static NotificationChannel defaultChannel; + public static void notifyCompat(NotificationManager notificationManager, int notificationId, Notification notification) { try { notificationManager.notify(notificationId, notification); @@ -22,4 +25,20 @@ //https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/ } } + + 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; + } + } diff --git a/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java b/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java --- a/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java @@ -79,7 +79,9 @@ id = 42; //A unique id to create only one notification } - Notification noti = new NotificationCompat.Builder(context) + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + Notification noti = new NotificationCompat.Builder(context, NotificationHelper.getDefaultChannelId(notificationManager)) .setContentTitle(device.getName()) .setContentText(message) .setContentIntent(resultPendingIntent) @@ -89,7 +91,6 @@ .setDefaults(Notification.DEFAULT_ALL) .build(); - NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationHelper.notifyCompat(notificationManager, id, noti); return true; diff --git a/src/org/kde/kdeconnect/Plugins/ReceiveNotificationsPlugin/ReceiveNotificationsPlugin.java b/src/org/kde/kdeconnect/Plugins/ReceiveNotificationsPlugin/ReceiveNotificationsPlugin.java --- a/src/org/kde/kdeconnect/Plugins/ReceiveNotificationsPlugin/ReceiveNotificationsPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/ReceiveNotificationsPlugin/ReceiveNotificationsPlugin.java @@ -105,7 +105,10 @@ } } } - Notification noti = new NotificationCompat.Builder(context) + + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + Notification noti = new NotificationCompat.Builder(context, NotificationHelper.getDefaultChannelId(notificationManager)) .setContentTitle(np.getString("appName")) .setContentText(np.getString("ticker")) .setContentIntent(resultPendingIntent) @@ -117,7 +120,6 @@ .setDefaults(Notification.DEFAULT_ALL) .build(); - NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationHelper.notifyCompat(notificationManager, "kdeconnectId:" + np.getString("id", "0"), np.getInt("id", 0), noti); } diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/NotificationUpdateCallback.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/NotificationUpdateCallback.java --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/NotificationUpdateCallback.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/NotificationUpdateCallback.java @@ -39,8 +39,9 @@ } else { title = res.getString(R.string.outgoing_file_title, device.getName()); } - notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - builder = new NotificationCompat.Builder(context) + + notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); + builder = new NotificationCompat.Builder(context, NotificationHelper.getDefaultChannelId(notificationManager)) .setSmallIcon(android.R.drawable.stat_sys_upload) .setAutoCancel(true) .setProgress(100, 0, false) diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareNotification.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareNotification.java --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareNotification.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/ShareNotification.java @@ -52,7 +52,7 @@ this.filename = filename; notificationId = (int) System.currentTimeMillis(); notificationManager = (NotificationManager) device.getContext().getSystemService(Context.NOTIFICATION_SERVICE); - builder = new NotificationCompat.Builder(device.getContext()) + builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.getDefaultChannelId(notificationManager)) .setContentTitle(device.getContext().getResources().getString(R.string.incoming_file_title, device.getName())) .setContentText(device.getContext().getResources().getString(R.string.incoming_file_text, filename)) .setTicker(device.getContext().getResources().getString(R.string.incoming_file_title, device.getName())) @@ -77,7 +77,7 @@ public void setFinished(boolean success) { String message = success ? device.getContext().getResources().getString(R.string.received_file_title, device.getName()) : device.getContext().getResources().getString(R.string.received_file_fail_title, device.getName()); - builder = new NotificationCompat.Builder(device.getContext()); + builder = new NotificationCompat.Builder(device.getContext(), NotificationHelper.getDefaultChannelId(notificationManager)); builder.setContentTitle(message) .setTicker(message) .setSmallIcon(android.R.drawable.stat_sys_download_done) diff --git a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java --- a/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -159,7 +159,9 @@ PendingIntent.FLAG_UPDATE_CURRENT ); - Notification noti = new NotificationCompat.Builder(context) + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + Notification noti = new NotificationCompat.Builder(context, NotificationHelper.getDefaultChannelId(notificationManager)) .setContentTitle(res.getString(R.string.received_url_title, device.getName())) .setContentText(res.getString(R.string.received_url_text, url)) .setContentIntent(resultPendingIntent) @@ -169,7 +171,6 @@ .setDefaults(Notification.DEFAULT_ALL) .build(); - NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationHelper.notifyCompat(notificationManager, (int) System.currentTimeMillis(), noti); } }