我正在使用react native on和android项目,我需要检测android设备的活动呼叫的呼叫状态,如来电、已连接等。
我还需要来电/出局手机的电话号码。
提前感谢!
发布于 2020-04-15 03:12:20
使用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,您可以从头到尾完整地了解如何拨打电话号码。
https://stackoverflow.com/questions/61215268
复制相似问题