{"action":"created","issue":{"url":"https://api.github.com/repos/katzer/cordova-plugin-background-mode/issues/131","repository_url":"https://api.github.com/repos/katzer/cordova-plugin-background-mode","labels_url":"https://api.github.com/repos/katzer/cordova-plugin-background-mode/issues/131/labels{/name}","comments_url":"https://api.github.com/repos/katzer/cordova-plugin-background-mode/issues/131/comments","events_url":"https://api.github.com/repos/katzer/cordova-plugin-background-mode/issues/131/events","html_url":"https://github.com/katzer/cordova-plugin-background-mode/issues/131","id":123654862,"number":131,"title":"[Question] Set Icon","user":{"login":"MazzMazz","id":10706512,"avatar_url":"https://avatars.githubusercontent.com/u/10706512?v=3","gravatar_id":"","url":"https://api.github.com/users/MazzMazz","html_url":"https://github.com/MazzMazz","followers_url":"https://api.github.com/users/MazzMazz/followers","following_url":"https://api.github.com/users/MazzMazz/following{/other_user}","gists_url":"https://api.github.com/users/MazzMazz/gists{/gist_id}","starred_url":"https://api.github.com/users/MazzMazz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MazzMazz/subscriptions","organizations_url":"https://api.github.com/users/MazzMazz/orgs","repos_url":"https://api.github.com/users/MazzMazz/repos","events_url":"https://api.github.com/users/MazzMazz/events{/privacy}","received_events_url":"https://api.github.com/users/MazzMazz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2015-12-23T12:47:40Z","updated_at":"2016-09-21T20:50:18Z","closed_at":null,"body":"On my Android 5.1.1 is only a white square next to the notification that the app is running. How can i set a custom icon there?"},"comment":{"url":"https://api.github.com/repos/katzer/cordova-plugin-background-mode/issues/comments/248738770","html_url":"https://github.com/katzer/cordova-plugin-background-mode/issues/131#issuecomment-248738770","issue_url":"https://api.github.com/repos/katzer/cordova-plugin-background-mode/issues/131","id":248738770,"user":{"login":"diegohdk","id":677172,"avatar_url":"https://avatars.githubusercontent.com/u/677172?v=3","gravatar_id":"","url":"https://api.github.com/users/diegohdk","html_url":"https://github.com/diegohdk","followers_url":"https://api.github.com/users/diegohdk/followers","following_url":"https://api.github.com/users/diegohdk/following{/other_user}","gists_url":"https://api.github.com/users/diegohdk/gists{/gist_id}","starred_url":"https://api.github.com/users/diegohdk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diegohdk/subscriptions","organizations_url":"https://api.github.com/users/diegohdk/orgs","repos_url":"https://api.github.com/users/diegohdk/repos","events_url":"https://api.github.com/users/diegohdk/events{/privacy}","received_events_url":"https://api.github.com/users/diegohdk/received_events","type":"User","site_admin":false},"created_at":"2016-09-21T20:50:18Z","updated_at":"2016-09-21T20:50:18Z","body":"Following @jrm0695's tip, I made a more flexible solution.\r\n\r\nThe steps are simple:\r\n\r\nFirst on `background-mode.js` just add `icon: 'icon'` to `exports._defaults`, starting on line 64;\r\n\r\nSecond, on `ForegroundService.java` make two changes:\r\n\r\n- Change line 142 to:\r\n```\r\n.setSmallIcon(getIconResId(settings.optString(\"icon\", \"\")));\r\n```\r\n- Change the method `getIconResId()` on line 168 to:\r\n```\r\nprivate int getIconResId(String icon) {\r\n        Context context = getApplicationContext();\r\n        Resources res   = context.getResources();\r\n        String pkgName  = context.getPackageName();\r\n\r\n        int resId;\r\n        resId = res.getIdentifier(icon, \"drawable\", pkgName);\r\n\r\n        return resId;\r\n    }\r\n```\r\n\r\nNow at your application just give a custom icon parameter when calling `cordova.plugins.backgroundMode.configure()` as described at the docs.\r\n\r\nNote: the icon must be in the drawables* directories to work.\r\n\r\nThis way the plugin still uses the default icon but allows you to give a custom icon at anytime. This is the expected behavior I think."}}
{"actor":{"display_login":"diegohdk"}}