Вот код, который я использую:
Код: Выделить всё
FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if (!task.isComplete()) {
System.out.println("PushNotification getInstanceId failed");
return;
}
deviceToken = task.getResult();
System.out.println("PushNotification device registration token retrieved successfully");
try {
callAgent.registerPushNotification(deviceToken).get();
}
catch (Exception e) {
System.out.println("Something went wrong while registering for Incoming Calls Push Notifications.");
}
try {
PushNotificationInfo notification = PushNotificationInfo.fromMap(pushNotificationMessageDataFromFCM);
}
catch (Exception e) {
System.out.println("Something went wrong while handling the Incoming Calls Push Notifications.");
}
}
});
Вот код услуги:
Код: Выделить всё
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private java.util.Map pushNotificationMessageDataFromFCM;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getNotification() != null) {
System.out.println("PushNotification");
}
else {
pushNotificationMessageDataFromFCM = remoteMessage.getData();
}
}
}
[*]Есть ли части, которые нужно разместить в одном месте, а части в другом?
[*]Почему создается впечатление, что FirebaseMessagingService никогда не используется?
[*]Почему создается впечатление, что код пытается что-то сделать с push-уведомлениями до того, как токен будет получен?
[*]Есть еще мысли?
< /ul>
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/792 ... oid-studio
Мобильная версия