ionic-cli icon indicating copy to clipboard operation
ionic-cli copied to clipboard

Ionic resource icon for Android push notifications

Open schoettler opened this issue 11 years ago • 35 comments

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.

schoettler avatar Oct 07 '15 20:10 schoettler

Second! Just looking for a way to do this too.

elloboblanco avatar Nov 02 '15 02:11 elloboblanco

+1

awebdeveloper avatar Nov 23 '15 06:11 awebdeveloper

I can't figure out a way to display an icon on my received push notifications.

ghost avatar Dec 04 '15 13:12 ghost

+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.

adyz avatar Dec 14 '15 15:12 adyz

+1

RafaelMCarvalho avatar Dec 20 '15 13:12 RafaelMCarvalho

+1

igordeoliveirasa avatar Dec 29 '15 10:12 igordeoliveirasa

+1

MazzMazz avatar Jan 16 '16 23:01 MazzMazz

+1

gauravarora avatar Feb 03 '16 10:02 gauravarora

+1

ronycohen avatar Feb 09 '16 12:02 ronycohen

+1

Samox avatar Feb 15 '16 22:02 Samox

Here is a solution

  1. Create a folder called push_icon in resources/android/
  2. Create the files in the format drawable-hopi-icon.png like you see in icon folder
  3. 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('-----------------------------------------------------------------------------------------');
});

awebdeveloper avatar Feb 18 '16 11:02 awebdeveloper

+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.

jakub-g avatar Feb 22 '16 16:02 jakub-g

+1

mainalikishan avatar Mar 03 '16 07:03 mainalikishan

+1

alejandromagnorsky avatar Mar 16 '16 07:03 alejandromagnorsky

+1

Remrem84 avatar Mar 25 '16 15:03 Remrem84

+1

pawurb avatar Apr 08 '16 13:04 pawurb

For anyone here for ionic2, you can:

  1. Use this generator: http://romannurik.github.io/AndroidAssetStudio/icons-notification.html

  2. 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
    
  3. stick this into gulpfile.js

    gulp.task('ic_notification', function() {
        gulp.src('./resources/android/ic_notification/**')
            .pipe(gulp.dest('./platforms/android/res'));
        });
    
  4. Add the 'ic_notification' task to the runSequence calls 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.

wli avatar Apr 14 '16 01:04 wli

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 avatar May 09 '16 11:05 boyfunky

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

wli avatar May 09 '16 21:05 wli

+1

shyamal890 avatar May 27 '16 09:05 shyamal890