我正在研究 react-native-callkeep 与 firebase FCM 通知的集成。 集成了 Callkeep,一旦触发 FCM 通知,我就会收到呼叫通知,如您在屏幕上看到的那样
但是当应用程序处于终止/退出或后台状态并且我在真实 Android 设备中单击“应答”按钮时,应用程序会卡住。
当我在 Android-Studio 中调试代码时,我发现了这个日志
D/RNCallKeep: [RNCallKeepModule][onReceive] ACTION_ANSWER_CALL
V/RNCallKeep: [RNCallKeepModule] sendEventToJS, eventName: RNCallKeepPerformAnswerCallAction, bound: true, hasListeners: true args : { NativeMap: {"withVideo":false,"callUUID":"b52560f4-2360-4c69-8b05-7530a1b7b2fe"} }
D/RNCallKeep: [RNCallKeepModule][onReceive] ACTION_AUDIO_SESSION
V/RNCallKeep: [RNCallKeepModule] sendEventToJS, eventName: RNCallKeepDidActivateAudioSession, bound: true, hasListeners: true args : null I/ReactNativeJS: 'answerCall', 'b52560f4-2360-4c69-8b05-7530a1b7b2fe'
D/RNCallKeep: [RNCallKeepModule] backToForeground, app isOpened ?true
I/TelecomFramework: VoiceConnectionService: answer TC@13_1: CS.an->H.CS.an@AAA
D/RNCallKeep: [VoiceConnection] onAnswer(int) executed
D/RNCallKeep: [VoiceConnection] onAnswer called, videoState: 0, answered: true
D/RNCallKeep: [VoiceConnection] onAnswer() executed
D/RNCallKeep: [VoiceConnection] onAnswer called, videoState: 0, answered: true
D/RNCallKeep: [VoiceConnection] onStateChanged called, state : 6
D/RNCallKeep: [VoiceConnection] onDisconnect executed
D/RNCallKeep: [VoiceConnectionService] deinitConnection:b52560f4-2360-4c69-8b05-7530a1b7b2fe
D/RNCallKeep: [VoiceConnectionService] stopForegroundService
我想一旦我点击“应答”按钮,它就会开始与 TELECOM_CONNECTION_SERVICE 通信,一旦它没有与电信服务建立任何连接,那么应用程序就会卡住。
我的callkeep集成代码是这样的
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
displayIncomingCall(remoteMessage);
});
还有
export const displayIncomingCall = remoteMessage => {
const {data} = remoteMessage;
const {customer_name, telephone} = data;
const uuid = uuidv4();
RNCallKeep.displayIncomingCall(
uuid,
`${telephone}`,
`${customer_name}`,
'generic',
true,
);
};
一旦单击“应答”按钮,即添加了 EventListner
export const answerCall = ({callUUID}) => {
console.log('answerCall', callUUID);
invokeApp({data: notificationData});
};
我想跳过此 VoiceConnectionService 步骤 一旦我点击“接听”按钮,应用程序就会进入前台 并在从 HeadlessJS 事件调用应用程序时传递一些数据到前台应用程序。
添加 RNCallKeep.backToForeground():
export const displayIncomingCall = remoteMessage => {
const {data} = remoteMessage;
const {customer_name, telephone} = data;
const uuid = uuidv4();
RNCallKeep.displayIncomingCall(
uuid,
`${telephone}`,
`${customer_name}`,
'generic',
true,
);
RNCallKeep.backToForeground()
};