我在Android应用程序中使用FirebaseMessaging进行即时消息传递。FirebaseMessaging Android有些消息丢失
对于从服务器到设备Android的消息,不会丢失消息。
但是从移动到服务器一些消息丢失...
服务器接收ACK消息,但在其他方向(移动到服务器)移动不接收ACK。
其结果是大约30%的消息丢失。如果我快速发送多条消息,会有更多的损失(40-60%)。如果我缓慢地发送多个消息,则有10%的消息丢失...
当我将消息发送到服务器时,我注意到在我的FirebaseMessagingService中,方法“onMessageSent”被10个消息模糊地调用。这是正常的吗? 为什么 “onMessageSent” 不是一次,只要消息被发送称为...
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/** constante pour renvoyer la position GPS */
public static final String BROADCAST_FIREBASE_FILTER= "android.intent.action.MY_APP_FIREBASE";
private DatabaseHelper helper;
@Override
public void onCreate() {
super.onCreate();
}
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Notification method below.
DebugLog.logw(TAG,"MESSAGE RECEIVED");
String clickAction = remoteMessage.getNotification().getClickAction();
[..]
}
// [END receive_message]
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String title, String messageBody,Intent intent2) {
intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent2,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
@Override
public void onDeletedMessages() {
super.onDeletedMessages();
DebugLog.logi(TAG, "onDeletedMessages");
}
@Override
public void onMessageSent(String s) {
super.onMessageSent(s);
DebugLog.logi(TAG, "onMessageSent = " + s);
}
@Override
public void onSendError(String s, Exception e) {
super.onSendError(s, e);
DebugLog.logi(TAG, "onSendError = " + s);
}
}
我在我的FragmentMessaging方法发送消息:
public void sendMessage(Message msg){
DebugLog.logd("FragmentMessagerie","sendMessage msg = " + msg.getMsg());
if(textMessage.getText().length()>0) {
final Message message = msg;
AtomicInteger atomicInteger = new AtomicInteger();
FirebaseMessaging fm = FirebaseMessaging.getInstance();
RemoteMessage rm = new RemoteMessage.Builder(senderID)
.setMessageId("myApp_" + atomicInteger.incrementAndGet() + System.currentTimeMillis())
.addData("action", "chat")
.addData("destinataire", String.valueOf(contact.getId()))
.addData("emetteur",username)
.addData("texte",msg.getMsg())
.setTtl(0)
.build();
fm.send(rm); // appel à fireBase pour l'envoi du message
[..]
textMessage.setText("");
} else {
[..]
}
}
}
我的问题是:
当发送消息(firebaseMessaging.send(remoteMessage))Firebase应该处理向服务器发送消息。
Android是否将消息错误地发送到Firebase?
还是Firebase将消息严重地发送到我的服务器?
在服务器上,我收到发送给手机的ACK消息。
在我的设备Android上,我没有收到ACK消息,当发送10条消息时,只有方法“onMessageSent”被调用了10次......这是正常的吗?
如何才能收到ACK消息设备Android到服务器?从我的设备?
在此先感谢您的帮助!