From 11f5d0404dbd3ab221ad9e99738c9654137f7d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sat, 31 Dec 2016 13:36:30 +0100 Subject: [PATCH] Notification shows app info with cordova-android 6.x [Fixes #212] --- src/android/ForegroundService.java | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/android/ForegroundService.java b/src/android/ForegroundService.java index bbc5554..f82edeb 100644 --- a/src/android/ForegroundService.java +++ b/src/android/ForegroundService.java @@ -209,10 +209,37 @@ public class ForegroundService extends Service { String pkgName = context.getPackageName(); String icon = settings.optString("icon", "icon"); - int resId = res.getIdentifier(icon, "drawable", pkgName); + // cordova-android 6 uses mipmaps + int resId = getIconResId(res, icon, "mipmap", pkgName); if (resId == 0) { - resId = res.getIdentifier("icon", "drawable", pkgName); + resId = getIconResId(res, icon, "drawable", pkgName); + } + + return resId; + } + + /** + * Retrieve resource id of the specified icon. + * + * @param res + * The app resource bundle. + * @param icon + * The name of the icon. + * @param type + * The resource type where to look for. + * @param pkgName + * The name of the package. + * + * @return The resource id or 0 if not found. + */ + private int getIconResId(Resources res, String icon, + String type, String pkgName) { + + int resId = res.getIdentifier(icon, type, pkgName); + + if (resId == 0) { + resId = res.getIdentifier("icon", type, pkgName); } return resId;