Notification shows app info with cordova-android 6.x [Fixes #212]

This commit is contained in:
Sebastián Katzer 2016-12-31 13:36:30 +01:00
parent 8d165cdf3a
commit 11f5d0404d

View File

@ -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;