-1

我在做android电话号码的处理,你可以知道是否有来电​​,即确认电话已被接听。使用以下代码进行调用:

Intent callIntent = new Intent (Intent.ACTION_CALL, Uri.parse (number));
startActivity (callIntent);

当您结束对我的应用程序的呼叫时,我想知道呼叫是否已接听以及是否可能是呼叫的持续时间。

4

1 回答 1

1

是的,你可以,为此你需要创建 BroadCastReceiver,例如

 <receiver android:name=".broadcast.DontMissReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
  </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")) {

            }
        }

    }
于 2013-06-04T18:39:52.557 回答