Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

App crashes on notification when in background #715

Closed
HanGmanXXL opened this issue Mar 17, 2016 · 13 comments
Closed

App crashes on notification when in background #715

HanGmanXXL opened this issue Mar 17, 2016 · 13 comments

Comments

@HanGmanXXL
Copy link

Actual Behaviour

The App crashes on notification, when in background. In App its all fine and works properly.
Receiving notifications when app is in background worked already but at a moments notice it stopped working.

Platform and Version

Android 6.0.1 - Nexus 5x
Android 5.1.1 - Sony Xperia Z3 Compact

Cordova v6.0.0
Plugin v1.6.0

Sample Push Data Payload

{
  "to": my_id,
  "data": {
      "message": "my message",
      "title": "my title"
  }
}

Sample Code that illustrates the problem

gcm = PushNotification.init({
      'android': {
        'senderID'           : my_sender_id,
        'icon'               : '',
        'iconColor'          : '',
        'sound'              : true,
        'vibrate'            : true,
        'clearNotifications' : true,
        'forceShow'          : false,
        'topics'             : []
      },
      'ios': {
        'alert'      : true,
        'badge'      : true,
        'sound'      : false,
        'clearBadge' : false
      },
      windows: {}
    });

gcm.on('notification', function(data) {
  alert(data.message);
});

I don't know how to debug this kind of crash.
Thanks for your support!

@jakub-g
Copy link
Contributor

jakub-g commented Mar 17, 2016

Which version of plugin? what device (Samsung, HTC, ...?)

@HanGmanXXL
Copy link
Author

Plugin v1.6.0

Sony Xperia Z3 Compact (Android 5.1.1)
Google Nexus 5x (Android 6.0.1)

@macdonst
Copy link
Member

@HanGmanXXL run adb logcat when you are reproducing the problem and pipe the input to a file. That should catch any crash. Then put the file up on gist or pastebin so we can look.

@wibimaster
Copy link

Hi,

I got the same problem ; send a notification, if the app is open and front, all is ok, if the app is collapsed or closed, I got an error popup "The application has been closed".

I launch adb logcat, and this is the output generated when a notification is received :
http://pastebin.com/1eyvCADU

I try on a Nexus 4, and the notification is send followed the example provided here (with node) :/

Cordova v6.0.1, Plugin v1.6.0 too

Thanks !

EDIT

Ok, I cannot really fix it because I'm not a Java-man, but the error comes from "setNotificationIconColor" function.
I just escape the call in GCMIntentService.java :
// setNotificationIconColor(extras.getString("color"), mBuilder, localIconColor);
and it works now, I can receive the notification.

I read the code and see the try catch :

        else if (localIconColor != null) {
            try {
                iconColor = Color.parseColor(localIconColor);
            } catch (IllegalArgumentException e) {
                Log.e(LOG_TAG, "couldn't parse color from android options");
            }
        }

But it seems that the error is not a "IllegalArgumentException" in my case...

@macdonst
Copy link
Member

@wibimaster can you post up your PushNotification.init and a sample push payload as well? Your bug is a really easy fix but I just want to make sure it is the same repo as @HanGmanXXL

@macdonst macdonst added bug and removed question labels Mar 18, 2016
@wibimaster
Copy link

I try many things, an example of init used (tried with "iconColor: ''" too):

            android: {
                senderID: '123456789123',
                icon: 'notification',
                iconColor: 'purple',
                sound: true,
                vibrate: true,
                clearNotifications: true,
                forceShow: false,
                topics: []
            },
            ios: {
                senderID: '',
                alert: false,
                badge: false,
                sound: false,
                clearBadge: false,
                gcmSandbox: false,
                topics: [],
                categories: {}
            },
            windows: {}

And same symptoms with all examples provided here, as this one (tried with a simple title + message notification too) :

var service = new gcm.Sender(apiKey);
var message = new gcm.Message();
message.addData('title', 'Test title');
message.addData('message', 'Test message');
message.addData('style', 'picture');
message.addData('picture', 'http://36.media.tumblr.com/c066cc2238103856c9ac506faa6f3bc2/tumblr_nmstmqtuo81tssmyno1_1280.jpg');
message.addData('summaryText', 'Test summary');
message.addData('ledColor', [0,255,0,255]);
service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) {
    if(err) console.error(err);
    else    console.log(response);
});

@macdonst
Copy link
Member

@HanGmanXXL okay, I've fixed this and published version 1.6.1 which is now available on NPM. Thanks for the excellent bug report.

@wibimaster
Copy link

Perfect ! It works great, many thanks 👍

@barryvdh
Copy link
Contributor

So does this error always occur, or only when trying to set the icon? (Need to know if I need to push out a new release for Android)

@macdonst
Copy link
Member

@barryvdh it only happens when you set iconColor to an empty string. I was protecting against a null but not the empty string. If you send an empty string to parseColor then an exception is throw that was not being caught which crashed the app.

So as long as you are not setting iconColor to an empty string you don't have to rush a new release out but I wanted to get the bug fix out there as the problem is easy to work around but causes a crash.

@HanGmanXXL
Copy link
Author

@macdonst Sorry for the late response. Thank you very much for fixing it so quickly. 👍

@macdonst
Copy link
Member

@HanGmanXXL no problem, I love good bug reports that I can actually reproduce.

@lock
Copy link

lock bot commented Jun 4, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

5 participants