Android Handle phone call

限于喜欢 提交于 2019-11-29 14:24:54

问题


I have audio recording, when a phone call come I need to stop the recording, how can I do this?


回答1:


You have to use the 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) {}
    } 
};

Make sure to include this permission in your Manifest:

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



回答2:


I've never tried to access the phone stuff on Android but check here -

http://developer.android.com/reference/android/telephony/package-summary.html

and here -

http://developer.android.com/reference/android/telephony/PhoneStateListener.html

and here -

http://developer.android.com/reference/android/telephony/TelephonyManager.html



来源:https://stackoverflow.com/questions/4324659/android-handle-phone-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!