我有录音,来电话时我需要停止录音,我该怎么做?
问问题
5608 次
2 回答
16
你必须使用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) {}
}
};
确保在您的清单中包含此权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
于 2010-12-01T13:16:25.957 回答
1
我从未尝试在 Android 上访问手机内容,但请查看此处 -
http://developer.android.com/reference/android/telephony/package-summary.html
和这里 -
http://developer.android.com/reference/android/telephony/PhoneStateListener.html
和这里 -
http://developer.android.com/reference/android/telephony/TelephonyManager.html
于 2010-12-01T13:20:18.387 回答