如何让状态拨出电话 [英] how to get the state for outgoing calls

查看:83
本文介绍了如何让状态拨出电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的onReceive 方法,我有这样的事情:

In the OnReceive method I have something like this:

    Bundle bundle=intent.getExtras();
   String phonenumber=intent.getStrngExtra(Intent.EXTRA_PHONE_NUMBER);

如何再检查一下,如果拨号呼叫仍然还是客户端挂了电话? 如何检查是否呼叫被应答?

How to chech if the dialing call is still on or the client hanged up the call? How to check if the call was answered?

我需要打印一个toat当客户端挂了电话或当被叫客户端应答呼叫。

I need to print up a toat when the client hanged up the call or when the called client answered to the call.

推荐答案

您可以使用下面的code处理呼叫状态:::

you can use the below code for handling call state:::

    private Runnable callMonitor = new Runnable() {
        public void run() {
            try {
                EndCallListener callListener = new EndCallListener();
                TelephonyManager mTM = (TelephonyManager)m_activity.getSystemService(Context.TELEPHONY_SERVICE);
                mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
            } catch(Exception e) {
                Log.e("callMonitor", "Exception: "+e.toString());
            }
        }
    };   

    private class EndCallListener extends PhoneStateListener {
        private boolean active = false;
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

            if(TelephonyManager.CALL_STATE_RINGING == state) {
                Log.i("EndCallListener", "RINGING, number: " + incomingNumber);
            }
            if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
                //wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
                active = true;
                Log.i("EndCallListener", "OFFHOOK");
            }
            if(TelephonyManager.CALL_STATE_IDLE == state) {
                //when this state occurs, and your flag is set, restart your app
                Log.i("EndCallListener", "IDLE");
                if (active) {
                    active = false;

                    // stop listening                   
                    TelephonyManager mTM = (TelephonyManager)m_activity.getSystemService(Context.TELEPHONY_SERVICE);
                    mTM.listen(this, PhoneStateListener.LISTEN_NONE);

                    // restart the inbox activity
//                  Intent intent = new Intent(m_activity, MDInboxActivity.class);
//                  m_activity.startActivity(intent);
                }
            }
        }
    }

这篇关于如何让状态拨出电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆