You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio集成Azure+Google FCM遇阻:推送注册与服务调用异常

Azure通信服务Android端后台来电推送配置问题

我在Android Studio中配置Azure通信服务,实现APP关闭状态下接收来电,但推送通知注册环节遇到问题。Azure官方教程未明确代码放置位置,我分别尝试将代码放在createAgent()函数和onCreate()函数末尾,虽然能成功获取设备注册token,但后续流程无进展。从日志输出来看,推送注册和来电推送处理的代码似乎在token获取完成前就已执行。

用到的代码片段

Firebase Token获取与推送注册代码

FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
        @Override
        public void onComplete(@NonNull Task<String> 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.");
            }
        }
    });

Firebase消息服务代码

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private java.util.Map<String, String> pushNotificationMessageDataFromFCM;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        if (remoteMessage.getNotification() != null) {
            System.out.println("PushNotification");
        }
        else {
            pushNotificationMessageDataFromFCM = remoteMessage.getData();
        }
    }
}

当前问题细节

  • 日志中已打印PushNotification device registration token retrieved successfully,但同时也打印了两个try块中的错误提示,说明推送注册和处理逻辑执行出问题
  • MyFirebaseMessagingService的onMessageReceived方法从未被触发,断点无响应,pushNotificationMessageDataFromFCM始终无法获取到FCM推送数据
  • 无论将代码放在onCreate()还是createAgent()中,问题都无法解决

疑问点

  • 是否有代码需要分开放置?
  • 为何FirebaseMessagingService未被调用?
  • 为何推送操作似乎在token获取前执行?
  • 其他相关建议?

内容的提问来源于stack exchange,提问作者pbhuter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 23:22:38