diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java index e8391f4f..d48c44af 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java @@ -29,6 +29,8 @@ import android.app.PendingIntent; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.os.Build; import android.os.Bundle; import android.provider.Settings; @@ -44,6 +46,8 @@ import org.kde.kdeconnect.Plugins.Plugin; import org.kde.kdeconnect.UserInterface.SettingsActivity; import org.kde.kdeconnect_tp.R; +import java.io.InputStream; + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener { /* @@ -322,18 +326,37 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. PendingIntent.FLAG_UPDATE_CURRENT ); + Bitmap largeIcon = null; + if (np.hasPayload()) { + int width = 64; // default icon dimensions + int height = 64; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + width = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width); + height = context.getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height); + } + final InputStream input = np.getPayload(); + largeIcon = BitmapFactory.decodeStream(np.getPayload()); + try { input.close(); } catch (Exception e) { } + if (largeIcon != null) { + //Log.i("NotificationsPlugin", "hasPayload: size=" + largeIcon.getWidth() + "/" + largeIcon.getHeight() + " opti=" + width + "/" + height); + if (largeIcon.getWidth() > width || largeIcon.getHeight() > height) { + // older API levels don't scale notification icons automatically, therefore: + largeIcon = Bitmap.createScaledBitmap(largeIcon, width, height, false); + } + } + } Notification noti = new NotificationCompat.Builder(context) .setContentTitle(np.getString("appName")) .setContentText(np.getString("ticker")) .setContentIntent(resultPendingIntent) .setTicker(np.getString("ticker")) .setSmallIcon(android.R.drawable.ic_dialog_alert) + .setLargeIcon(largeIcon) .setAutoCancel(true) .setLocalOnly(true) // to avoid bouncing the notification back to other kdeconnect nodes .setDefaults(Notification.DEFAULT_ALL) .build(); - NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); try { // tag all incoming notifications