Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getToken: null token. (android) #212

Open
Tolfx opened this issue Jul 7, 2022 · 0 comments
Open

getToken: null token. (android) #212

Tolfx opened this issue Jul 7, 2022 · 0 comments

Comments

@Tolfx
Copy link

Tolfx commented Jul 7, 2022

When I call the method window.cordova.plugins.firebase.messaging.getToken() I get null.

And not entirely sure what I'm doing wrong, what I've read I should just call it and get a token.
And when I looked at the Java file and compare it with the older versions I can't really understand what went wrong.

I fixed it by doing like this:

    @CordovaMethod
    private void getToken(String type, final CallbackContext callbackContext) {
        // type can still be null, so if we call type.isEmpty() and is null it will crash.
        if (type != null && type.isEmpty()) {
            callbackContext.sendPluginResult(
                    new PluginResult(PluginResult.Status.OK, (String)null));
        } else {
            firebaseMessaging.getToken().addOnCompleteListener(cordova.getActivity(), task -> {
                if (task.isSuccessful()) {
                    callbackContext.success(task.getResult());
                } else {
                    callbackContext.error(task.getException().getMessage());
                }
            });
        }
    }

But if there is another solution I wouldn't mind getting a answer. Since I rather just not mess with the source unless I really need to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant