xamarin-plugins icon indicating copy to clipboard operation
xamarin-plugins copied to clipboard

Android: body_loc_key only working when app in background

Open CR4567 opened this issue 8 years ago • 1 comments

Hi,

sometimes android has really a weird behavior.... :-) I'm using the body_loc_key for translation of my push notifications (as described here https://developers.google.com/cloud-messaging/http-server-ref). The weird thing is that everything works as expected, if message arrives while app is in background. If app is open the normal body variable is used. Or if I send a blank message only with the body_loc_key the message is completely empty. Is the message treated different when open? I thought the only difference is that if it's open the OnMessage function is triggered, but the shouldn't be a problem. Right?

The translation files are available in the resource folder and as I said, working when in background.

CR4567 avatar Oct 13 '16 16:10 CR4567

Since I couldn't find a solution for the problem, I wrote a simple code snippet for the PushNotificationGCMListener:

int identifier = Resources.GetIdentifier(message, "string", PackageName);

                if (identifier != 0)
                {
                    if (parameters.ContainsKey(PushNotificationKey.Args))
                    {
                        var args = parameters[PushNotificationKey.Args];
                        message = Resources.GetString(identifier, (Java.Lang.Object)args);
                    }
                    else { 
                        message = Resources.GetString(identifier);
                    }
                }

It checks wether there is a Resource with the given name and than checks for arguments. At the end overrides the original message with the translated message from the resource file.

Does that make sense to you? If so, is it possible to integrate into your branch?

CR4567 avatar Oct 17 '16 16:10 CR4567