How to get outgoing call is answered in Android

假如想象 提交于 2019-12-11 02:54:22

问题


I need a way to get the the status when a outgoing call is answered. However, in the OFFHOOK state I am also using to call for the outgoing call(ACTION_CALL). How can I add the awnsered state without overriding the outgoing call activity?

public class OutgoingBroadcastReceiver extends BroadcastReceiver {

private Intent mIntent;
private String phonenumber = null;
public static boolean wasRinging;

@Override
public void onReceive(Context context, Intent intent) {
    mIntent = intent;

    MyPhoneStateListener phoneListener = new MyPhoneStateListener(context);
    TelephonyManager telephony = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

    phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

}

public class MyPhoneStateListener extends PhoneStateListener {
    private final Context context;

    public MyPhoneStateListener(Context context) {
        this.context = context;

    }

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {


        switch (state) {

        case TelephonyManager.CALL_STATE_IDLE: 

            wasRinging = true;
            break;

        case TelephonyManager.CALL_STATE_OFFHOOK:

                Log.e("%%%%%%%%%%%%%%%%%%%%%%%%%%%t", "OFFHOOK");
            if (UIUDialer.isOutgoingCall() == true) {

                //Do my work when outgoing call is detected
            } 

            else if (!wasRinging)
            {

                    Log.e("%%%%%%%%%%%%%%%%%%%%%%%%%%%t", "WASRINGING");
                //Do my work when outgoing call is awnsered

            }



            context.sendBroadcast(new Intent("finish_incoming"));
            wasRinging = true;
            break;

        case TelephonyManager.CALL_STATE_RINGING:

            wasRinging = true;
            break;
        }
    }

}

}


回答1:


There is no public API available for this.




回答2:


Why don't you just use the boolean wasRinging?
(you'll have to make it static and remove the initialization, though)



来源:https://stackoverflow.com/questions/9705314/how-to-get-outgoing-call-is-answered-in-android

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