
[英]not receiving push notification from firebase But with Pusher app
[英]Android app not receiving FCM push notification from Python Server (iOS is)
我正在制作今年早些时候制作的 iOS 应用程序的 Android 版本。 我有一个 Python Flask API,它应该在调用某个端点时通过 Firebase 云消息传递向 Android 和 iOS 设备发送推送通知。
我的 iOS 应用程序运行良好,但在 Android 上我没有收到任何通知(无论是在前台还是后台)。
在我的 Python 代码中,我使用的是MulticastMessage
:
push_notification = messaging.MulticastMessage(
device_tokens,
notification=messaging.Notification(title=title, body=message),
data=data,
apns=messaging.APNSConfig(
payload=messaging.APNSPayload(
messaging.Aps(sound="default")
)
),
android=messaging.AndroidConfig(
notification=messaging.AndroidNotification(
sound="default"
)
)
)
response = messaging.send_multicast(push_notification)
device_tokens
是我要向其发送通知的设备的注册令牌列表。 我确认其中一个令牌确实是我的 Android 客户端正在使用的令牌。 data
是以下形式的字典:
{
"uid": "<user-uid-here>"
}
在客户端,我试图非常密切地遵循文档。 我添加了我的google-services.json
文件,在 Gradle 文件中添加并应用了插件,并添加了 Firebase Messaging 依赖项。 然后我创建了一个消息服务并更新了我的应用程序清单:
public class MessagingService extends FirebaseMessagingService {
public MessagingService() {
super();
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.w("Debug", "RECEIVED MESSAGE");
}
}
<!--Inside application tag-->
<service
android:name=".model.MessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@mipmap/ic_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
我应该提到它在某些时候有点工作(有时我会收到通知,有时我不会),但我不记得我做了什么破坏了它(如果我做了什么的话)。
我在很多地方用谷歌搜索过,但似乎没有任何效果。
我错过了什么吗? 我非常有信心问题不在于服务器,因为 iOS 应用程序正在很好地处理通知。
注意:我希望能够从前台和后台状态接收消息。
编辑:我在模拟器上运行它; 也许这可能与问题有关? 我记得有时在设备很长时间没有收到通知之前......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.