在Firebase中,令牌始终为null [英] Token is always null in Firebase
问题描述
我正在尝试通过以下简单代码获取令牌以在我的应用中使用云消息传递:
I am trying to get a token to use cloud messaging in my app with the following simple code :
String token = FirebaseInstanceId.getInstance().getToken();
我试图在StackOverflow上到处寻找那些有相同问题但找不到任何解决方案的人...当然,我遵循了有关安装的官方Google文档(多次),我的令牌是从未生成.
I have tried to look everywhere on StackOverflow for people who had the same problem and couldn't find any solution... I have, of course, followed the official Google Documentation about the installation (several times) and my token was never generated.
有人知道为什么我无法获得有效的令牌吗?
Any idea why I can't get a valid token?
谢谢!
推荐答案
好,我设法自己找到了解决方案,我花了很多时间弄清楚它,因此我认为分享它是一个好主意万一有人遇到同样的问题,该解决方案.
OK, I managed to find the solution by myself, it took me a lot of time to figure it out so I thought it would be a good idea to share the solution in case someone gets the same issue.
所以问题出在我在AndroidManifest.xml
(在<application>
标记内)使用了这一行的事实:
So the problem came from the fact that I used this line in my AndroidManifest.xml
(inside <application>
tag) :
tools:node="replace"
必须通过以下操作将其删除或更改:
This had to be removed or changed by the following :
tools:node="merge"
否则,Firebase将无法在您的应用程序中运行.至少,这是我修复应用程序以最终获得有效令牌的方式!
Otherwise, Firebase will not work in your app. At least, it's how I fixed my app to finally get a valid token!
希望这对其他人有帮助!
Hope this will help someone else!
这篇关于在Firebase中,令牌始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!