简体   繁体   中英

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. 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). I have also used many 3rd party sensor testing apps but none of them is working for S10. Does anyone know what Samsung has changed? how we can access S10 proximity sensor programmatically? 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. To test the proximity sensor just acquire a wake lock created with PROXIMITY_SCREEN_OFF_WAKE_LOCK parameter.

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:

1: light sensor 2: Proximity sensor

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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