Android应用程序未收到firebase通知
我的android应用程序未收到任何firebase通知。当我从firebase控制台发送消息时,它显示流程已完成,当行展开时,它显示0 message send,屏幕截图如下 消息的到期时间设置为1分钟 我已经添加了Android应用程序未收到firebase通知,android,firebase,firebase-notifications,Android,Firebase,Firebase Notifications,我的android应用程序未收到任何firebase通知。当我从firebase控制台发送消息时,它显示流程已完成,当行展开时,它显示0 message send,屏幕截图如下 消息的到期时间设置为1分钟 我已经添加了FirebaseMessagingService,FirebaseInstancedService,并在清单中添加了如下服务 <service android:name=".service.TjssFireBaseInstanceIdService">
FirebaseMessagingService
,FirebaseInstancedService
,并在清单中添加了如下服务
<service android:name=".service.TjssFireBaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name=".service.TjssFireBaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
这是应用程序类的onCreate
方法
@Override
public void onCreate() {
super.onCreate();
mGlide = Glide.with(this);
String token = FirebaseInstanceId.getInstance().getToken();
if (token != null)
M.log("Firebase Token", token);
}
我在logcat输出中有一个有效的令牌
我做了他们说的所有文档,但它不起作用。我错过了什么重要的东西吗?你把
谷歌服务.json
放在你的应用文件夹里了吗。如果没有,请把它放在应用程序文件夹中,并查看此文件中的信息,它是否与您的项目相关。尝试通过选择应用程序包名称发送通知。我希望这能奏效。谢谢请确保在发送通知时应用程序未运行。如果你的应用程序位于前台,那么你将无法接收通知
如果您希望在应用程序位于前台时接收通知,请按以下方式编辑您的服务:
public class TjssFireBaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getNotification() != null) {
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("Val", remoteMessage.getNotification().getTitle());
startActivity(i);
}
}
@Override
public void onDeletedMessages() {
super.onDeletedMessages();
}}
当收到通知且您的应用程序位于前台时,上述代码将启动您的主要活动。在您的onCreate应用程序中添加此代码
FirebaseApp.initializeApp(this);
这意味着这里的上下文共享您完整的manifesh和应用程序文件,您在应用程序文件中初始化了FirebaseInstance吗?我已经编辑了我的问题并添加了应用程序类的
onCreate
。以及如何初始化Firebase实例?请检查将包从清单复制到Firebase控制台中的包名称
FirebaseApp.initializeApp(this);