gpt4 book ai didi

android - 如何在Android中接听去电

转载 作者:行者123 更新时间:2023-11-29 00:40:29 24 4
gpt4 key购买 nike

我需要一种方法来获取拨出电话被接听时的状态。但是,在摘机状态下,我也用于调用去电(ACTION_CALL)。如何在不覆盖拨出调用 Activity 的情况下添加 awnsered 状态?

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;
}
}

}

最佳答案

没有可用的公共(public) API。

关于android - 如何在Android中接听去电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9705314/

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