未收到通知,但在安卓系统中使用Firebase和Reformation2似乎发送成功



我正在处理通知,但在A发送通知后,B无法收到通知。我已经添加了Toast进行检查,我可以看到发送成功,但看起来没有调用onMessageReceived。你能帮我哪里出错吗?非常感谢。

舱单

<service android:name=".notifications.FirebaseService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_SERVICE"/>
</intent-filter>
</service>
<service
android:name=".notifications.FirebaseMessaging"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>

这是onMessageReceived((。我看不到"收到的信息">

public class FirebaseMessaging extends FirebaseMessagingService
{
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
//get current user from share preference
SharedPreferences sp = getSharedPreferences("SP_USER", MODE_PRIVATE);
String savedCurrentUser = sp.getString("Current_USER", "None");
Toast.makeText(this, "message received", Toast.LENGTH_SHORT).show();
String sent = remoteMessage.getData().get("sent");
String user = remoteMessage.getData().get("user");
FirebaseUser fUser = FirebaseAuth.getInstance().getCurrentUser();
if(fUser != null && sent.equals(fUser.getUid())) {
if(!savedCurrentUser.equals(user)){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
sendOAndAboveNotification(remoteMessage); 
}else {
sendNormalNotification(remoteMessage);
}
}
}

}

这是我发送通知的地方,我可以看到"响应"消息

public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds: dataSnapshot.getChildren()) {
Token token = ds.getValue(Token.class);
Data data = new Data(uid,name+":"+message,"New Message",destinationUid,R.drawable.icon_byb_final7);
Sender sender = new Sender(data, token.getToken());
apiService.sendNotification(sender)
.enqueue(new Callback<Response>() {
@Override
public void onResponse(Call<Response> call, retrofit2.Response<Response> response) {
Toast.makeText(MessageActivity.this,"Response"+response.message(),Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<Response> call, Throwable t) {
}
});
}
}

看起来代码是正确的,如果我同时使用两个模拟器手机,它就不起作用。如果你看到同样的问题,你可以尝试在你的手机上安装应用程序,并从模拟器中尝试一个。它对我有用。

相关内容

  • 没有找到相关文章