gpt4 book ai didi

Android 处理电话

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:14:06 24 4
gpt4 key购买 nike

我有录音,来电时我需要停止录音,我该怎么做?

最佳答案

你必须使用PhoneStateListener:

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

// somewhere else
private PhoneStateListener mPhoneListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber) {
try {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
// do something...
break;

case TelephonyManager.CALL_STATE_OFFHOOK:
// do something...
break;

case TelephonyManager.CALL_STATE_IDLE:
// do something...
break;
default:
Log.d(TAG, "Unknown phone state=" + state);
}
} catch (RemoteException e) {}
}
};

确保在您的 list 中包含此权限:

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

关于Android 处理电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4324659/

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