我正在处理android手机号码,您可以知道是否拨打了电话,即确认电话被接听。使用以下代码进行调用:
Intent callIntent = new Intent (Intent.ACTION_CALL, Uri.parse (number));
startActivity (callIntent);
当你结束对我的应用程序的呼叫时,这时我想知道呼叫是否被应答,以及呼叫的持续时间
是的,你可以,为此你需要创建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")) {
}
}
}