React-native RNCallkeep.displayIncomingCall在应用处于killed模式时无法在Android中工作

cvxl0en2  于 2023-04-12  发布在  React
关注(0)|答案(1)|浏览(120)

我正在尝试使用音频视频通话功能制作一个应用程序。我使用了React-native-callkeep来通知接收者有关通话的信息。通话流程如下:当呼叫者点击呼叫启动按钮时,接收者将收到FCM推送通知,其中包含加入房间的数据
我想在接收器应用处于killed状态时唤醒接收器屏幕。为此,我使用react-native-callkeep。我调用displayIncomingCall()函数来唤醒屏幕,当应用处于killed状态时,它在IOS中工作正常,但在Android中不工作。

//function to call the incoming call screen

export const Display = async (uuid, handle, localizedCallerName) => {
  RNCallKeep.displayIncomingCall(uuid, handle, localizedCallerName);
};
// inside index.js
messaging().setBackgroundMessageHandler(async (data) => {
  if (data.data?.description == "audio" || data.data?.description == "video") {
    Platform.OS == "android"
      ? Display(
          "11edc52b-2918-4d71-9058-f7285e29d894",
          "Shadowz Calling",
          data?.data?.sent_by_name
        )
      : Display(
          "11edc52b-2918-4d71-9058-f7285e29d894",
          "Shadowz Calling",
          data?.data?.sent_by_name,
          "number",
          "false"
        );
  }
});
wwodge7n

wwodge7n1#

触发BackgroundMessageHandler需要发送data typefirebase通知,不能通过firebase控制台发送,需要向https://fcm.googleapis.com/fcm/send API发送POST请求,示例代码如下。

const sendPush = async () => {
let data = {
  method: 'POST',
  body: JSON.stringify({
    to: '<device token>',
    priority: 'high',
    data: {
      description:"audio"// your data here
    },
  }),
  headers: {
    'Content-Type': 'application/json',
    Authorization:
      '<server key>',//copy this from your project in firebase console
  },
};
return fetch('https://fcm.googleapis.com/fcm/send', data)
  .then(response => response.json())
  .then(json => console.log('FCM Response---', json));

};

你也可以用postman来测试。
阅读更多关于FCM通知类型-https://www.javatpoint.com/firebase-types-of-message

相关问题