[question]: OneSignal PlayerID Null on Initial App Startup (Android)
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
- [X] I agree to follow this project's Code of Conduct
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!
Hi @maoryadin, thanks for reaching out with your question.
If
getDeviceState()is called too early it will benullor 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..
Hi @maoryadin, addSubscriptionObserver should be added after OneSignal.initWithContext.
Did you test and it is not being triggered for you?
@maoryadin just checking to see if you received our previous response?