Closed ngseba closed 2 years ago
I managed to figure it out. I also installed MoEngage SDK in order to provide push notification campaigns and inApps. So i added the following in my apps Android Manifest:
<service
android:name="com.moengage.hms.pushkit.MoEPushKitMessageService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
Also noticed that inside the hms-push-react-native package there is an intent like this declared in AndroidManifest. So the one that I added, inside my own manifest, overriding the one from the package, reason for which logs were not triggered and the callbacks were not triggered as well from this library's service.
I'll leave this here in case someone else has a similar problem.
Description
When trying to apply for a token using
HmsPushInstanceId.getToken("")
it works on EMUI >=10. However, when I try doing the same thing on EMUI < 10, it returns an empty string. Upon inspecting the documentation I found out that: If the response to a token request is empty or a token changes, an event listener needs to be used to receive the requested or updated token. The event listener for the new tokens is HmsPushEvent.onTokenReceived.Expected behavior
I expect the onTokenReceived handler to work.
Implementation details
So I implemented the following:
It seemed that it should work, but it didn't. Since I couldn't figure out if I subscribe to the token method in an appropiate manner, I wanted to debug if the native code works, if my logs would show up there, clearly there would be a problem in my React-Native code.
Logs
Upon inspecting the native code I found out that there are services registered for those event listeners. And saw that there are logs implemented. Upon carefully inspecting the following logs:
Here I can see that the service is successfully registered and I am interested particularly in the logs "onNewToken to host app." and "onNewToken to host app with bundle." these logs are from the base service class, but the methods that make those logs appear in the first place, should also trigger another function, the one that is responsible with passing the token to React-Native, that one has some logs in it as well (so next I'm going to look for those logs in the debugging console). Basically I was expecting the log: __"HMSSDK_HmsPushMessageService onNewToken "__ to appear as well (since that is the method that also sends the token to React-Native and for some reason that doesn't happen). And right after that, service is destroyed.
Screenshot that proves that the expected method which should send params to React-Native doesn't show any log:
I'm not that familiar with Android lifecycle, but is the service supposed to be destroyed like that? And even if all the logs should be the same as they are here, why doesn't the onTokenReceived trigger on React-Native?
Environment