作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要一种方法来获取拨出电话被接听时的状态。但是,在摘机状态下,我也用于调用去电(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/
我是一名优秀的程序员,十分优秀!