PhoneStateListener导致传出调用出现问题

时间:2013-12-25 06:18:08

标签: phone-state-listener

phonestatelistener用于监听来电时,外拨电话会自动结束。 这是我的代码,执行此操作时会阻止拨出电话:

public class CallHelper {
    public String number;
    private Context ctx;
    private TelephonyManager tm;

    private CallStateListener callStateListener;
    private OutgoingReceiver outgoingReceiver;
    SharedPreferences trackMeData;
    public CallHelper(Context ctx) {
        this.ctx = ctx;

        number ="";
        callStateListener = new CallStateListener();
        outgoingReceiver = new OutgoingReceiver();
        trackMeData = ctx.getSharedPreferences("LockedSIM", 0);

    }

    private class CallStateListener extends PhoneStateListener {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                number = incomingNumber;
                sendsmstoph(number);
                System.out.println("Incomgin");
                Toast.makeText(ctx, "Incoming: " + incomingNumber,Toast.LENGTH_LONG).show();
                break;
            }
        }
    }

    public class OutgoingReceiver extends BroadcastReceiver {
        public OutgoingReceiver() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Toast.makeText(ctx, "Outgoing: " + number, Toast.LENGTH_LONG).show();
            sendsmstoph(number);
        }

    }

0 个答案:

没有答案