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

[question]: OneSignal PlayerID Null on Initial App Startup (Android) #1530

Closed
1 task done
maoryadin opened this issue Jun 23, 2023 · 4 comments
Closed
1 task done

Comments

@maoryadin
Copy link

maoryadin commented Jun 23, 2023

How can we help?

Hello everyone,

I'm facing an issue on Android where the OneSignal PlayerID is always null during the initial startup of the application (i.e., the first time after installation). As a result, I am unable to save the PlayerID to my database until the second launch of the app.

Steps to Reproduce:

Install the application on an Android device.
Launch the application.
Attempt to retrieve and save the OneSignal PlayerID. (OneSignal.getDeviceState())
Actual Behavior:
The OneSignal PlayerID is null on the initial launch, which prevents its storage in the database.

Expected Behavior:
The OneSignal PlayerID should be available during the initial launch of the application, allowing it to be saved in the database right away.

I'm looking for guidance on how to handle this situation. What can I do to ensure that the PlayerID is available and savable on the first launch? Any suggestions or best practices would be highly appreciated.

Thank you in advance for your help!

Environment:
OneSignal SDK version: 4.5.1

Code of Conduct

  • I agree to follow this project's Code of Conduct
@nan-li
Copy link
Contributor

nan-li commented Jun 25, 2023

Hi @maoryadin, thanks for reaching out with your question.

If getDeviceState() is called too early it will be null or not available. There is a server call to register the device and get a playerID.

You can use the addSubscriptionObserver method to get a playerID from OneSignal when a notification subscription property changes. Does this fulfill your needs?

Thanks!

@maoryadin
Copy link
Author

Hi @maoryadin, thanks for reaching out with your question.

If getDeviceState() is called too early it will be null or not available. There is a server call to register the device and get a playerID.

You can use the addSubscriptionObserver method to get a playerID from OneSignal when a notification subscription property changes. Does this fulfill your needs?

Thanks!

Does the addSubscriptionObserver should be defined before OneSignal.SetAppId?
Because i think if it will be defined after, it will not be triggered..

@nan-li
Copy link
Contributor

nan-li commented Jun 26, 2023

Hi @maoryadin, addSubscriptionObserver should be added after OneSignal.initWithContext.

Did you test and it is not being triggered for you?

@jennantilla
Copy link
Contributor

@maoryadin just checking to see if you received our previous response?

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

3 participants