1

在拨出电话的情况下,会自动抛出摘机状态嗨,伙计们,首先我为我的英语道歉。

好吧,在我的应用程序中,我正在监视每个呼叫,之前和之后。但是就在通话开始之后,所以我与“响铃”状态无关,但是我的应用程序正在触发一个假的“摘机”状态。当我拨打电话(拨出电话)时,我的应用程序在振铃后立即设置摘机状态。有了这个,我正在监视一个我不应该的呼叫,因为该呼叫无法应答。

有人已经有这个问题了吗?

AndroidManifest.xml

    <receiver
        android:name=".CallStateBroadcastReceiver">
        <intent-filter>
          <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
    </receiver>

    <receiver
        android:name=".OutgoingCallBroadcastReceiver">
        <intent-filter>
          <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
    </receiver>

CallStateBroadcastReceiver:

    CallStatePhoneStateListener phoneListener = new CallStatePhoneStateListener(context, intent);
    TelephonyManager telephony = (TelephonyManager) context.getSystemService(
            Context.TELEPHONY_SERVICE);

        telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

CallStatePhoneStateListener:

@Override
public void onCallStateChanged(int state, String incomingNumber) {

    switch (state) {
        case TelephonyManager.CALL_STATE_IDLE:

            // do something
            break;

        case TelephonyManager.CALL_STATE_OFFHOOK:

            // do something
            break;

        case TelephonyManager.CALL_STATE_RINGING:

            // do something
            break;
}

OutgoingCallBroadcastReceiver:

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    if (bundle == null)
        return;

    String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    // just save the number
}
4

2 回答 2

0

我希望这对你有用。

public void onCallStateChanged(int state, String incomingNumber) {
    super.onCallStateChanged(state, incomingNumber);

    Log.d("main", "incoming call receiver.");
    PowerManager pm = (PowerManager) c
            .getSystemService(Context.POWER_SERVICE);
    boolean isScreenOn = pm.isScreenOn();

    switch (state) {
    case TelephonyManager.CALL_STATE_IDLE:
        Log.v("idle state", "CALL_STATE_IDLE");
        // CALL_STATE_IDLE;


        if (ring == true && callReceived == false && CheckMissCall.isReject==true) {

            Log.v("missed call", "Missed call from : " + incomingNumber);
            if(CheckMissCall.isShown)
            {
                c.stopService(new Intent(c, Unlock_hud.class));

            }

            flag = true;
            if (prefs.getBoolean("main_state", true) )
            {
                Intent inter = new Intent(c, MissCall.class);
                inter.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                inter.putExtra("CellNumber", incomingNumber);
                c.startActivity(inter);
            }

        }


        break;
    case TelephonyManager.CALL_STATE_OFFHOOK:
        // CALL_STATE_OFFHOOK;
        callReceived = true;
        Log.v("call received", "CALL_STATE_OFFHOOK  " + incomingNumber);        

        break;
    case TelephonyManager.CALL_STATE_RINGING:
        ring = true;
        // CALL_STATE_RINGING
        Log.v("call ringing", "CALL_STATE_RINGING  " + incomingNumber);
        Log.d("flags", "flags: " + flag);
        if (flag) {

            //cut = true;
            //flag = false;
            CheckMissCall call = new CheckMissCall(c);
            call.setName(incomingNumber);
            call.setNumber4Sms(incomingNumber);
            call.setContactPhoto();

            Log.d("main", "state ringing");
            prefs = PreferenceManager.getDefaultSharedPreferences(c);

            if (!prefs.getBoolean("main_state", false)) {

                return;
            }       

            if (CheckMissCall.isRunning) {

                return;
            }
            else {
                Log.d("main", "EEEEEEEEEEEEEEEE:  Unlock hud");
                Intent in = new Intent(c, Unlock_hud.class);
                in.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
                c.startService(in);

                // c.stopService(new Intent(c, Unlock_hud.class));
            }
        }
        break;
于 2014-07-30T05:37:26.090 回答
0

取一个静态字符串,例如:- prev_state 并在每个案例示例中将电话的状态存储在该字符串中,如果您想知道拨出电话是如何断开的,那么应该这样做,

   if(state==TelephonyManager.CALL_STATE_IDLE)
{ Log.d(TAG, "CALL_STATE_IDLE==>"+incoming_nr);
                      {
                   if((prev_state==TelephonyManager.CALL_STATE_OFFHOOK))
                             {  
                        prev_state=state;  
                       // do something when the Call  is ended 
                              }
                       }
}

希望能帮助到你 :)

于 2013-01-18T11:31:49.567 回答