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

发布于 2025-01-08 08:58:31 字数 96 浏览 6 评论 0原文

我编写了一个基于接近传感器的应用程序,但我希望能够让用户能够更改传感器的灵敏度。 是否可以?如果是的话怎么办?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌能量女王 2025-01-15 08:58:31

只需“实现 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;
        }
    }

Just "implements SensorEventListener" and follow the code :

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;
        }
    }
笑梦风尘 2025-01-15 08:58:31

我认为这是不可能的。接近传感器由操作系统管理。为了保护用户,应用程序不能在没有 root 访问权限的情况下直接更改操作系统文件。

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.

吐个泡泡 2025-01-15 08:58:31

Android 中定义的传感器 API 将接近度定义为布尔值,即 NEAR(1) 或 FAR(0)。我认为“灵敏度”指的是阈值距离,低于该阈值距离传感器将接近度报告为“NEAR”。

Android 上的光/接近传感器的更多详细信息< /strong>

Android(最高 v4.1“jelly-bean”)不会将接近距离参数作为其传感器 API 的一部分公开

您有以下选项:

  • 修改传感器 HAL 以向接近传感器添加可配置阈值。

  • 直接与接近传感器驱动程序交互(通常是 sys-fs 条目)。
    根据所使用的光/接近传感器硬件,
    这可能在少数设备上可行,而在其他设备上则不然。

此外,为了进行此类“系统级”修改,Android 设备肯定需要 root。

The sensor API defined in Android defines the proximity to be a boolean i.e NEAR(1) OR FAR(0). By "sensitivity", i presume you mean the threshold distance below which the proximity sensor reports proximity as NEAR.

More details of Light/Proximity sensor on Android.

Android (upto v4.1 "jelly-bean") does NOT expose the proximity distance parameter as part of its sensor API.

You have the following options:

  • modify the sensor-HAL to add a configurable threshold to proximity sensor.

  • interact with the proximity sensor driver directly (usually a sys-fs entry).
    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文