简体   繁体   English

如何在三星 Galaxy S10 或 S10+ 中测试接近传感器?

[英]How to test proximity sensor in Samsung galaxy S10 or S10+?

I want to test proximity sensor on Samsung newer model (s10 or s10+), I have used the old conventional way to register the listener for the proximity sensor and it is working for all the device except these 2 ones.我想在三星较新的型号(s10 或 s10+)上测试接近传感器,我使用旧的传统方法来注册接近传感器的侦听器,它适用于除这两个设备之外的所有设备。 I have searched over the internet and come to know that S10 has proximity sensor under the display (a blinking pixel lights up during call etc).我在互联网上搜索并知道 S10 的显示屏下方有接近传感器(在通话期间闪烁的像素亮起等)。 I have also used many 3rd party sensor testing apps but none of them is working for S10.我还使用了许多 3rd 方传感器测试应用程序,但它们都不适用于 S10。 Does anyone know what Samsung has changed?有谁知道三星改变了什么? how we can access S10 proximity sensor programmatically?我们如何以编程方式访问 S10 接近传感器? I have tried the below code but it is always toasting far.我已经尝试了下面的代码,但它总是很远。

@Override
   public void onSensorChanged(SensorEvent event) {
       if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
           if (event.values[0] >= -SENSOR_SENSITIVITY && event.values[0] <= SENSOR_SENSITIVITY) {
               //near
               Toast.makeText(getApplicationContext(), "near", Toast.LENGTH_SHORT).show();
           } else {
               //far
               Toast.makeText(getApplicationContext(), "far", Toast.LENGTH_SHORT).show();
           }
       }
   }

   @Override
   public void onAccuracyChanged(Sensor sensor, int accuracy) {
       Toast.makeText(getApplicationContext(), "accuracy changed", Toast.LENGTH_SHORT).show();
   }

您可以使用密码 *#77692#在三星 Galaxy S10 上测试接近传感器

Try not to use the sensor API directly.尽量不要直接使用传感器 API。 To test the proximity sensor just acquire a wake lock created with PROXIMITY_SCREEN_OFF_WAKE_LOCK parameter.要测试接近传感器,只需获取使用 PROXIMITY_SCREEN_OFF_WAKE_LOCK 参数创建的唤醒锁。

It will not help to get the measured distance, but the screen will start to turn off/on when you put your palm over the sensor.获取测量距离无济于事,但是当您将手掌放在传感器上时,屏幕将开始关闭/打开。

class ProximityMgr(context: Context) {
    private val powerManager: PowerManager = context.getSystemService()!!
    private val wakeLock: PowerManager.WakeLock

    init {
        wakeLock = powerManager.newWakeLock(
                PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, 
                "lock:proximity_screen_off")
    }

    fun acquire() {
        if (powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
            if (wakeLock.isHeld) {
                wakeLock.release()
            }
            wakeLock.acquire(WAKE_LOCK_TIMEOUT_MS)
        } else {
            Log.w(TAG, "not supported")
        }
    }

    fun release() {
        if (wakeLock.isHeld)
            wakeLock.release()
    }

    companion object {
        private const val TAG = "ProximitySensor"
        private const val WAKE_LOCK_TIMEOUT_MS: Long = 2 * 3600 * 1000
    }
}

This snippet was taken from this answer .这个片段取自这个答案

Here is how to turn on and test the proximity sensor.这是打开和测试接近传感器的方法。

Dial *#77692# you wil get two sensors to test:拨打 *#77692# 你会得到两个传感器进行测试:

1: light sensor 2: Proximity sensor 1:光线传感器 2:接近传感器

You can't turn it on and keep it on.你不能打开它并保持它。 We just can test it by turning it on afterward it goes to off modus.我们可以通过在它进入关闭模式后打开它来测试它。 Very strange from Samsung.三星很奇怪。

Maybe the next update will give the possibility to keep it on.也许下一次更新将提供保持它的可能性。 So the screen won't go unlocked in the pocket.所以屏幕不会在口袋里解锁。 Hope this can help you.希望这可以帮到你。

In simple terms(non-programatically) Method1 star hash zero star hash( #0 #)on dialer A block of options will be there(red,green,blue,vibration,camera)in that select proximity sensor.now it will show the lux(luminious intensity)amount more light more lux.check that wise also.also u can hover now the display appears green with a vibration.简单来说(非编程) Method1 star hash zero star hash( #0 #)on dialer A block of options will there (red,green,blue,vibration,camera)in选择接近传感器。现在它会显示勒克斯(发光强度)量更多的光,更多勒克斯。检查这也很明智。你现在也可以悬停显示器显示为绿色并伴有振动。 Method2 Do a call.During the call the right top area (left side of camera)a white dot will be blinking in the display itself.(looks like a pixel dot).now hover and check.方法2 拨打电话。在通话过程中,右上方区域(相机左侧)显示屏本身会闪烁一个白点。(看起来像一个像素点)。现在悬停并检查。

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

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