Android Firebase在应用程序运行时不发送通知?
我在这里搜索了这些问题,但我发现的都是关于应用程序未运行时的问题 在我的情况下,在我从Firebase控制台发送文本通知后,应用程序会在以下情况下收到通知:Android Firebase在应用程序运行时不发送通知?,android,firebase,android-webview,Android,Firebase,Android Webview,我在这里搜索了这些问题,但我发现的都是关于应用程序未运行时的问题 在我的情况下,在我从Firebase控制台发送文本通知后,应用程序会在以下情况下收到通知: 应用程序被终止(根本不运行) 应用程序位于后台(但未打开/隐藏) 应用程序是打开的,但手机屏幕本身处于“关闭”状态。(我必须单击硬按钮使屏幕再次变亮,然后滑动它以查看正在打开的应用程序) 我的问题是: 如果应用程序处于打开状态(屏幕处于打开状态且应用程序处于活动状态-我触摸屏幕以避免屏幕熄灭),我不会收到通知是否正常 感谢您的高级帮助。在F
感谢您的高级帮助。在Firebase中推送通知: 当您的应用程序被终止并且在后台时,您的
onMessageReceived
方法将不会被调用。您的通知将根据文档放在系统托盘中。您可以从默认启动器类检索通知
<application
android:name=".AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".view.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
当您的应用处于活动状态且处于前台时,您将收到推送通知,您的onMessageReceived
将被调用
MyFirebaseMessagingService.Java
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
String notificationtype, id, title, message, messagebody;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Displaying data in log
// String message = remoteMessage.getNotification().getBody().toString();
messagebody = remoteMessage.getData().toString();
// sendNotification(message);
notificationtype=remoteMessage.getData().get("notification_type");
id=remoteMessage.getData().get("id");
title=remoteMessage.getData().get("title");
message=remoteMessage.getData().get("message");
}
private void showNotification(String messageBody, String notificationtype, String title, String id) {
}
嗨,普拉迪普,谢谢你的回复。实际上,我甚至还需要知道前台应用和后台应用的确切区别。首先,我认为“前台应用”是:用户正在使用该应用。。。。它是开放的,用户正在应用程序上“玩”。“后台应用”是指:该应用未被使用,但该应用仍在Android手机的“最近打开的程序”列表中。“应用程序被杀死”是:用户清除了“最近打开的程序”中的应用程序。但似乎我错了。似乎“应用程序在后台”是:应用程序未打开,也不在“最近打开的程序”中,但服务仍在运行。例如WhatsApp。即使用户当前未使用WA,也不在“最近打开的程序”中“但WA服务仍在后台运行。这就是为什么我们可以收到通知,如果有消息来。而“WA被杀”就是我们“强行阻止”WA。。。所以WA根本不可用,并且在有人发送消息时不会显示通知。我说的对吗?当你关闭应用程序时,不会调用Firebase服务,当应用程序被关闭时,Firebase服务也不会运行。当再次打开应用程序时,会调用Firebase服务。请你向我解释一下,“关闭应用程序”是否等于“强制停止应用程序”?换句话说,要终止应用程序-我需要执行以下步骤:转到应用程序管理器->选择要终止的应用程序->然后单击强制停止按钮。谢谢你,pradeep。是的,“杀死应用程序”=“强制停止应用程序也是同样的方式。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
String notificationtype, id, title, message, messagebody;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Displaying data in log
// String message = remoteMessage.getNotification().getBody().toString();
messagebody = remoteMessage.getData().toString();
// sendNotification(message);
notificationtype=remoteMessage.getData().get("notification_type");
id=remoteMessage.getData().get("id");
title=remoteMessage.getData().get("title");
message=remoteMessage.getData().get("message");
}
private void showNotification(String messageBody, String notificationtype, String title, String id) {
}