Notification

jack s 5 years ago

Hello,
I'm using traccar push notification, but I got InvalidRegistration error response.
Can you help?

Regards,

Anton Tananaev 5 years ago

My guess there's some issue with the token. You should probably provide more details.

jack s 5 years ago

This is my config:

Notification config image

Anton Tananaev 5 years ago

Did you manually set user token? Who told you to do that?

jack s 5 years ago

I did not see any notificationtoken in user attributes, I set it manually.
And when I tracked the code in debug mode I got error in completed(Object o) function
InvalidRegistration error response.

@Override
    public void sendSync(long userId, Event event, Position position) {
        final User user = Context.getPermissionsManager().getUser(userId);
        if (user.getAttributes().containsKey("notificationTokens")) {

            Notification notification = new Notification();
            notification.body = NotificationFormatter.formatShortMessage(userId, event, position).trim();

            Message message = new Message();
            message.tokens = user.getString("notificationTokens").split("[, ]");
            message.notification = notification;

            Context.getClient().target(url).request()
                    .header("Authorization", "key=" + key)
                    .async().post(Entity.json(message), new InvocationCallback<Object>() {
                @Override
                public void completed(Object o) {
                }

                @Override
                public void failed(Throwable throwable) {
                    LOGGER.warn("Firebase notification error", throwable);
                }
            });
        }
    }

I did not know where is the variable KEY_TOKEN assigned a value in android app?

public final static String KEY_TOKEN = "keyToken";
Anton Tananaev 5 years ago

You set it incorrectly. It should a Firebase device token, not your server key.