如何改变安卓接近感应器的灵敏度?

2022-08-31 00:00:00 sensors android proximity

我编写了一个基于接近传感器的应用,但我希望能够让用户能够更改传感器的灵敏度。 有可能吗?如果是,应如何操作?


解决方案

只需"实现SensorEventListener"并遵循代码:

public void onCallStateChanged(int state, String incomingNumber) {
        switch (state) {
        case TelephonyManager.CALL_STATE_IDLE:
            System.out.println("My Call IDLE");
            CallState = false;
            StartAudioSpeacker();
            System.out.println("Is phone speaker : "+ audioManager.isSpeakerphoneOn());
            if (audioManager.isSpeakerphoneOn()) {
                audioManager.setSpeakerphoneOn(false);
                mSensorManager.unregisterListener(this);
            }
            break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
            System.out.println("My Call OFFHOOK");
            CallState = true;
            StartAudioSpeacker();
            System.out.println("Is phone speaker : "+ audioManager.isSpeakerphoneOn());
            break;
        case TelephonyManager.CALL_STATE_RINGING:
            System.out.println("My Call RINGING");
            break;
        }
    }

相关文章