其他分享
首页 > 其他分享> > Android接近传感器仅在三星设备中出现问题

Android接近传感器仅在三星设备中出现问题

作者:互联网

避免问题的具体方案:
三星设备中的活动行为与每次检测到更改时的方式不同,为了接近,它仅在SAMSUNG设备上调用onPause()/ onResume().

我正在清除onPause()中的接近传感器,导致三星设备独有的行为.

希望这可以为任何面临此问题的人节省一些时间.我从onPause()中删除了清除邻近侦听器的调用,现在它在所提到的设备上按预期工作.

更新:

下面提到的不是唯一的问题,接近传感器不一致地以这种方式表现.另一个问题是l-o-c:

if(!mWakeLock.isHeld())mWakeLock.acquire();

随机地,if()为所提到的设备返回false,因此并不总是调用mWakeLock.acquire().

可能相关的信息:

mWakeLock = mPowerManager.newWakeLock(field, getLocalClassName()); 

哪里

field = PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK or 32

我的接近传感器代码只能正常工作
1.三星GT-I9082 Android 4.2.2(API 17)[duos grand]
2.三星SM-G925I Android 5.1.1(API 22)[s6 edge]

编码:

 sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    sensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    ...new SensorEventListener() {
                @Override
                public void onSensorChanged(SensorEvent event) {
                    if (event.sensor.getType() == Sensor.TYPE_PROXIMITY) {
                        if (event.values[0] <= 5) { //Sleep
                            turnOffScreen();
                        } else { //Wake
                            turnOnScreen();
                        }...
 // registering listener with SensorManager.SENSOR_DELAY_NORMAL);  

问题:
两台设备上接近传感器返回的记录值会有波动,即使我们将手放在手机上持续几秒钟也是如此; 10-15没有移动它.
喜欢:
三星6优势 –

02-10 20:12:36.532: D/SensorManager(3467): Proximity, val = 8.0  [far]
02-10 20:12:36.532: D/SensorManager(29335): Proximity, val = 8.0  [far]
02-10 20:12:36.532: D/DisplayPowerController(3467): [sensor] setProximitySensorEnabled::unregisterListener
02-10 20:12:36.532: D/PowerManagerService(3467): [s] DisplayPowerCallbacks : onProximityNegative()
02-10 20:12:36.562: I/Sensors(3467): Proximity old sensor_state 33554560, new sensor_state : 33554432 en : 0
02-10 20:12:36.632: I/Sensors(3467): Proximity old sensor_state 33554944, new sensor_state : 33555072 en : 1
02-10 20:12:36.642: D/SensorManager(29335): registerListener :: 5, TMD4903 Proximity Sensor, 200000, 0,  
02-10 20:12:36.652: D/SensorManager(29335): Proximity, val = 8.0  [far]
02-10 20:12:36.662: I/Sensors(3467): ProximitySensor - 8(cm)
02-10 20:12:36.672: D/SensorManager(29335): Proximity, val = 8.0  [far]
02-10 20:12:41.752: I/Sensors(3467): Proximity old sensor_state 33554560, new sensor_state : 33554432 en : 0
02-10 20:12:41.822: I/Sensors(3467): Proximity old sensor_state 33554432, new sensor_state : 33554560 en : 1
02-10 20:12:41.842: D/SensorManager(29335): registerListener :: 5, TMD4903 Proximity Sensor, 200000, 0,  
02-10 20:12:41.842: D/SensorManager(29335): Proximity, val = 8.0  [far]
02-10 20:12:41.872: I/Sensors(3467): ProximitySensor - 8(cm)
02-10 20:12:41.872: D/SensorManager(29335): Proximity, val = 8.0  [far]
02-10 20:12:50.482: I/Sensors(3467): ProximitySensor - 0(cm)
02-10 20:12:50.482: D/SensorManager(29335): Proximity, val = 0.0  [close]
02-10 20:12:50.482: D/DisplayPowerController(3467): [sensor] setProximitySensorEnabled::registerListener
02-10 20:12:50.482: D/SensorManager(3467): registerListener :: 5, TMD4903 Proximity Sensor, 200000, 0,  
02-10 20:12:50.482: D/SensorManager(3467): Proximity, val = 0.0  [close]
02-10 20:12:50.482: D/PowerManagerService(3467): [s] DisplayPowerCallbacks : onProximityPositive()
02-10 20:12:50.482: D/PowerManagerService(3467): [s] DisplayPowerCallbacks : onProximityPositive()

三星Duos:与上面的8.0不同,波动值在0.0和5.0之间不同

>有哪些其他方法或排列组合可以成功和准确地应用于解决此问题?
>是不是因为传感器不同; GP2A接近传感器和APDS-9930 / QPDS-T930 Proximity&光吗?

我已经花了很长时间才这样做……徒劳无功

解决方法:

事实证明这是三星设备的注册问题,这里是一个页面集合,可以帮助任何人面对这个:

>使用onWindowFocusChanged.这对我来说很有意义,我与onPause()相关的实现也是成功的.
来源及说明:activity-onpause-to-handle-focus
是什么帮助了我:而不是onPause();

@覆盖
    public void onWindowFocusChanged(boolean hasFocus){
        super.onWindowFocusChanged(hasFocus);
        如果(!hasFocus){
                    clearProximityListeners();
        }
    }
> Issue 74464:Activity#onPause called without Activity#onResume, or can Context#registerReceiver failed
>更多参考:
从相当不同的方面,Bug取消注册…奥托巴士..报价:For us, this only appears on Samsung devices. And after a quick search,…

如果有更清晰的话,请编辑,更正,改进答案.希望它节省一些时间.

标签:android-sensors,android,samsung-mobile,proximity,proximitysensor
来源: https://codeday.me/bug/20190929/1830750.html