来自PhoneStateListener :: onCallStateChanged的IncomingNumber在Samsung A5~Android上为空

时间:2015-08-04 19:41:47

标签: android

我遇到 PhoneStateListener :: onCallStateChanged 的问题,当我使用这个特定的三星A5(Kitkat 4.4.4)设备时,它总是有一个空的incomingNumber 。当我使用其他设备时,它并没有发生,这意味着当我使用其他设备时,incomingNumber不为空。

我已经设置了此权限:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

这是我的PhoneStateListener类:

private class CallStateListener extends PhoneStateListener {
    boolean wasRinging = false;
    boolean accepted = false;
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        penelpon = incomingNumber;
        Toast.makeText(ctx,"Incoming: "+incomingNumber,Toast.LENGTH_LONG).show();
        switch (state) {
        case TelephonyManager.CALL_STATE_RINGING:
            // called when someone is ringing to this phone
            wasRinging = true;
            ada_panggilan = true;
            //Toast.makeText(ctx,"Incoming: "+incomingNumber,Toast.LENGTH_LONG).show();
            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            // accepted
            if(wasRinging){
                //Toast.makeText(ctx,"Diterima: "+incomingNumber,Toast.LENGTH_LONG).show();
                SafedriveActivity.is_call_accepted = true;
                accepted = true;
            }
            ada_panggilan = true;
            break;
        case TelephonyManager.CALL_STATE_IDLE:
            if(wasRinging){     // ditolak, kirim pesan
                ada_panggilan = true;
                if(!accepted) {
                    //Toast.makeText(ctx, "Ditolak: ngirim pesan ke: " + incomingNumber, Toast.LENGTH_LONG).show();
                    SafedriveActivity.is_call_accepted = false;
                    if(Statics.preferences.getBoolean(Statics.IS_SMS_AUTO_REPLY_ENABLED_PHONE,true)) {
                        sendMessage();
                    }
                }else{
                    //Toast.makeText(ctx,"Habis diterima, ditutup: "+incomingNumber,Toast.LENGTH_LONG).show();
                    SafedriveActivity.is_call_accepted = true;
                }
            }
            break;
        }
    }
}

在这种情况下, penelpon 为空。

为什么这只发生在三星A5?

提前致谢。

0 个答案:

没有答案