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

如何在应用关闭或Chat Activity销毁时检测ZegoCloud来电?

ZegoCloud 音视频通话来电唤醒问题解决方案

1. 修正来电Activity的Manifest配置

你的IncomingCallDialog设置了android:exported="false",当应用在后台或进程被杀死时,外部服务(比如Zego的唤醒逻辑)无法启动这个Activity。需要调整配置:

<activity
    android:name=".zegInvi.callwithinvitation.call.IncomingCallDialog"
    android:exported="true"
    android:launchMode="singleTop"
    android:theme="@style/dialogActivityTheme">
    <!-- 添加匹配来电邀请的Intent Filter -->
    <intent-filter>
        <action android:name="com.yourpackage.action.INCOMING_CALL" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

替换com.yourpackage.action.INCOMING_CALL为你业务中实际使用的action,或者Zego SDK指定的action字段

2. 完善后台服务的前台类型配置(Android 12+)

CallBackgroundService作为通话后台服务,在Android 12及以上系统中必须指定前台服务类型为phoneCall,否则系统会限制服务启动:

<service
    android:name=".zegInvi.callwithinvitation.call.CallBackgroundService"
    android:enabled="true"
    android:exported="false"
    android:foregroundServiceType="phoneCall" />

同时要确保服务启动时调用startForeground(),传入通话类型的通知,保证服务能在后台持续运行。

3. 添加Android 13+通知权限

Android 13及以上系统需要申请通知权限才能在后台显示来电通知,进而唤起来电界面,在Manifest中补充权限:

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

并在应用运行时动态申请该权限。

4. 配置离线推送通道

当应用完全关闭时,必须依赖第三方推送(如FCM、小米推送等)接收Zego的来电邀请并唤醒应用:

  • 在Manifest中配置对应推送服务的Receiver和Service
  • 在Zego控制台上传推送平台的证书信息
  • 在代码中初始化推送服务并与Zego SDK绑定,确保来电邀请能通过推送给到设备

5. 设备唤醒逻辑补充

虽然已声明WAKE_LOCK权限,接收来电时需要主动唤醒设备屏幕,保证来电界面能正常显示:

PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (powerManager != null && !powerManager.isInteractive()) {
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(
            PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            "yourapp:call_wake_lock"
    );
    wakeLock.acquire(30000); // 唤醒30秒供用户响应来电
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 13:53:13