简体   繁体   English

如何更改Android接近传感器的灵敏度?

[英]How to change Android proximity sensor sensitivity?

I coded an app based on proximity sensor , but I would like to be able to give users the ability to change the sensitivity of the sensor. 我编写了一个基于接近传感器的应用程序,但我希望能够为用户提供更改传感器灵敏度的功能。 Is it possible? 可能吗? If yes how to do it? 如果是,该怎么办?

Just "implements SensorEventListener" and follow the code : 只需“实现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;
        }
    }

The sensor API defined in Android defines the proximity to be a boolean ie NEAR(1) OR FAR(0). Android中定义的传感器API将接近程度定义为布尔值,即NEAR(1)或FAR(0)。 By "sensitivity", i presume you mean the threshold distance below which the proximity sensor reports proximity as NEAR. 我认为“灵敏度”是指阈值距离,低于该阈值距离,接近传感器报告接近为NEAR。

More details of Light/Proximity sensor on Android . Android上光/接近传感器的更多详细信息。

Android (upto v4.1 "jelly-bean") does NOT expose the proximity distance parameter as part of its sensor API . Android(最高v4.1“ jelly-bean”)不会在其传感器API中公开接近距离参数

You have the following options: 您有以下选择:

  • modify the sensor-HAL to add a configurable threshold to proximity sensor. 修改传感器HAL ,向接近传感器添加可配置的阈值。

  • interact with the proximity sensor driver directly (usually a sys-fs entry). 直接与接近传感器驱动程序进行交互 (通常是sys-fs条目)。
    Depending upon the light/proximity sensor hardware in use, 取决于所使用的光线/接近传感器硬件,
    this maybe possible on few devices and not on others. 在少数设备上而不是其他设备上,这可能是可能的。

Also one would definitely require the Android device to be rooted for such "system-level" modifications. 同样肯定会要求将Android设备植根于此类“系统级”修改。

I dont think this is possible. 我认为这是不可能的。 The proximity sensor is managed by the operating system. 接近传感器由操作系统管理。 To protect users apps can't directly change os files without root access. 为了保护用户,没有超级用户访问权限的应用程序无法直接更改os文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM