我正在处理Android手机号码,您可以知道是否进行了通话,即确认通话已被应答。使用以下代码进行呼叫:
Intent callIntent = new Intent (Intent.ACTION_CALL, Uri.parse (number));
startActivity (callIntent);
当您结束对我的应用程序的回叫时,那时我想知道呼叫是否已被应答以及是否可能是呼叫的持续时间。
答案 0 :(得分:1)
是的,你可以,为此你需要有意图创建BroadCastReceiver 例如
<receiver android:name=".broadcast.DontMissReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
然后在Receiver上
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if (action.equalsIgnoreCase(PHONE_ACTION)) {
this.receivePhoneCall(context, intent);
}
}
private void receivePhoneCall(Context context, Intent intent) {
String curState = intent.getExtras().getString("state");
if (curState.equalsIgnoreCase("RINGING")) {
} else
if (curState.equalsIgnoreCase("IDLE") && state.length() > 0) {
if (!state.equalsIgnoreCase("OFFHOOK")) {
}
}
}