Ionic resource icon for Android push notifications
Hey Ionic!
Would be nice if we could automatically set an icon for multiple resolutions as a custom push notification icon, as an addition to the app's icon & splash screen.
Second! Just looking for a way to do this too.
+1
I can't figure out a way to display an icon on my received push notifications.
+1
I use phonegap-plugin-push plugin https://github.com/phonegap/phonegap-plugin-push for push notifications
I generate "old" icons with ionic resources command even if I don't use ionic in my project at all.
After that I generate a new png with a new name with this tool: http://romannurik.github.io/AndroidAssetStudio/icons-notification.html and paste all the generated folders in the platforms/android/res folder with the "merge" options. The notification icon must have a different name, not icon.png and when I init the push plugin I use the name of my new file here:
"android": {
senderID: vv.params.googleGCMProjectNumber,
icon: "ic_stat_icon_material",
iconColor: "grey"
},
and the large icon from the JSON sent as push:
"GCM": {
title: "Large Icon",
message: "Loaded from drawables folder",
image: "icon"
}
where icon is the name of the file generated by ionic.
Tested on two devices so far. Works fine.
+1
+1
+1
+1
+1
+1
Here is a solution
- Create a folder called push_icon in resources/android/
- Create the files in the format drawable-hopi-icon.png like you see in icon folder
- Create a after_prepare hook
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var inputFolder = path.join(__dirname, '../../', 'resources/android/push_icon/');
var outputFolder = path.join(__dirname, '../../', '/platforms/android/res/');
console.log('------------------------------------------------------------------------------------------');
console.log("Running hook: "+path.basename(process.env.CORDOVA_HOOK));
console.log('------------------------------------------------------------------------------------------');
fs.readdir(inputFolder, function(err, list) {
list.forEach(function(file){
if (file.indexOf('drawable') === 0) {
var destFolder = file.replace('-icon.png','');
fs.createReadStream(inputFolder+file)
.pipe(fs.createWriteStream(outputFolder + destFolder + '/notify.png'));
console.log('# ' + file + ' --> ' + destFolder);
}
});
console.log('-----------------------------------------------------------------------------------------');
});
+1. please let us know if you consider the feature valuable, so maybe someone from community will send a PR for that
If you're unfamiliar with the context: in Android 5.0+, push notification icon has to be two-color: transparent background + white foreground; otherwise the default app icon is taken, and anything non-transparent is displayed as white (so very likely, the user will see a white square)
Now, to prevent that, you can have a separate icon only for push notifications, and pass that name to the cordova push plugin.
I'm for now using a combination of solutions from @adyz and @awebdeveloper i.e. generate icons via a website, commit them to git to a custom folder, then copy the images to platform/android/res in a hook.
+1
+1
+1
+1
For anyone here for ionic2, you can:
-
Use this generator: http://romannurik.github.io/AndroidAssetStudio/icons-notification.html
-
Put your icons in
resources/android/ic_notification/. It should look like this:- resources/android/ic_notification/drawable-hdpi-v11/ic_notification.png - resources/android/ic_notification/drawable-hdpi/ic_notification.png - resources/android/ic_notification/drawable-mdpi-v11/ic_notification.png - resources/android/ic_notification/drawable-mdpi/ic_notification.png - resources/android/ic_notification/drawable-xhdpi-v11/ic_notification.png - resources/android/ic_notification/drawable-xhdpi/ic_notification.png - resources/android/ic_notification/drawable-xxhdpi-v11/ic_notification.png - resources/android/ic_notification/drawable-xxhdpi/ic_notification.png - resources/android/ic_notification/drawable-xxxhdpi-v11/ic_notification.png - resources/android/ic_notification/drawable-xxxhdpi/ic_notification.png -
stick this into gulpfile.js
gulp.task('ic_notification', function() { gulp.src('./resources/android/ic_notification/**') .pipe(gulp.dest('./platforms/android/res')); }); -
Add the 'ic_notification' task to the
runSequencecalls for 'build' and 'watch':gulp.task('watch', ['clean'], function(done){ runSequence( ['sass', 'html', 'fonts', 'scripts', 'ic_notification'], function(){ gulpWatch('app/**/*.scss', function(){ gulp.start('sass'); }); gulpWatch('app/**/*.html', function(){ gulp.start('html'); }); buildBrowserify({ watch: true }).on('end', done); } ); }); gulp.task('build', ['clean'], function(done){ runSequence( ['sass', 'html', 'fonts', 'scripts', 'ic_notification'], function(){ buildBrowserify().on('end', done); } ); });
I think this whole process can be generalized and put into a plugin that should be included in https://github.com/driftyco/ionic-gulp-tasks.
am i the only one experiencing this but all the icons generated via http://romannurik.github.io/AndroidAssetStudio/icons-notification.html are just all white circles. i dont see my icon at all. @wli
@boyfunky notification icons are only two colors - white or transparent. The white circle implies that your icon has a circle shape. You probably want some kind of transparency so you get some kind of shape.
+1