gpt4 book ai didi

react-native - 如何在 React Native 中获取电话状态

转载 作者:行者123 更新时间:2023-12-04 10:13:12 26 4
gpt4 key购买 nike

我正在使用 react native on 和 android 项目,我需要检测 android 设备的 actives 调用的调用状态,如传入、连接等。

我也需要传入/传出手机的电话号码。

提前致谢!

最佳答案

使用 react native,您可以使用 react-native-call-state检查调用的状态,使用如下:

import React, { DeviceEventEmitter } from 'react-native'
import CallState from 'react-native-call-state';

componentWillMount() {
CallState.startListener();
this.subscription = DeviceEventEmitter.addListener('callStateUpdated', data => { console.warn(JSON.stringify(data)); });
}

componentWillUnmount() {
CallState.stopListener();
}


使用java,你可以使用 TelephonyManager ,设置如下:

 public class MyPhoneStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
handleRinging(incomingNumber);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
handleOffHook();
break;
case TelephonyManager.CALL_STATE_IDLE:
handleIdle();
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}

要获取调用的电话号码,您可以使用 react-native-call-detection , here你可以有一个完整的例子来说明如何制作,从头到尾。

关于react-native - 如何在 React Native 中获取电话状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61215268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com