Android接近传感器问题仅在Samsung设备中 [英] Android proximity sensor issue only in Samsung devices
问题描述
避免出现问题的特定方案:
三星设备中活动"的行为有所不同,其方式是每次检测到变化时(接近)都会导致在三星设备上仅调用onPause()/onResume()
.
Specific scenario to avoid problems:
Behaviour for Activity in Samsung devices was different in the manner that every time there was a change detected, for proximity, it resulted in a call to onPause()/onResume()
ONLY on SAMSUNG devices.
我正在清理onPause()
中的接近传感器,这导致了三星设备独有的行为.
I was clearing the proximity sensors in onPause()
which resulted in a behaviour unique to Samsung devices.
希望这可以为面临此问题的任何人节省一些时间.我从onPause()
中删除了清除邻近侦听器的调用,现在它可以在提到的设备上按预期工作.
Hope this saves some time for anybody who's facing this. I removed the call of clearing proximity listeners from onPause()
and now it works as expected on the mentioned devices.
更新:
UPDATE:
下面提到的不是唯一的问题,接近传感器并非始终以这种方式运行.另一个问题是l-o-c:
What is mentioned below is not the only issue, the proximity sensor does not consistently behave in that manner. The other issue is a l-o-c:
if (!mWakeLock.isHeld()) mWakeLock.acquire();
随机地,if()
对于所提及的设备返回false,因此mWakeLock.acquire()
并不总是被调用.
Randomly, the if()
returns false for the mentioned devices hence mWakeLock.acquire()
isn't always called.
可能相关的信息:
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]
My proximity sensor code works incorrectly only on
1. Samsung GT-I9082 Android 4.2.2 (API 17) [duos grand]
2. Samsung 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 edge-
the problem:
Logged values returned by proximity sensor on both devices fluctuate, even while we place a hand over the phones constantly for a few seconds; 10-15 without moving it.
Like:
Samsung 6 edge-
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:波动值在0.0和5.0中有所不同,与上面的8.0不同
Samsung Duos: the fluctuation values differ in 0.0 and 5.0 unlike 8.0 above
-
还有哪些其他方法或排列组合可以成功且准确地用于解决此问题?
What are there other ways or permutation-combinations which can be applied successfully and accurately to solve this issue?
是因为传感器不同吗? GP2A接近传感器和APDS-9930/QPDS-T930接近&轻吗?
Is it because of different sensors; GP2A Proximity Sensor and APDS-9930/QPDS-T930 Proximity & Light ?
已经花了很多时间..徒然
have already spent quite some time on it..in vain
推荐答案
因此,这是Samsung设备的已注册问题,这是一组页面,可以帮助面临此问题的任何人:
So turns out this is a registered issue with Samsung devices, here is a collection of pages which could help anybody facing this:
-
使用 onWindowFocusChanged .这对我来说很有意义,并且与onPause()有关的实现在遵循该实现时也很成功.
来源和解释:活动-onpause-to-handle-focus
是什么帮助了我:而不是在onPause()
中;
Use onWindowFocusChanged. This made sense to me and my implementation related to onPause() was successful on following the same.
Source and Explanation: activity-onpause-to-handle-focus
What helped me: instead of inonPause()
;
@Override 公共无效onWindowFocusChanged(boolean hasFocus){ super.onWindowFocusChanged(hasFocus); if(!hasFocus){ clearProximityListeners(); } }
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if(!hasFocus){ clearProximityListeners(); } }
问题74464:Activity#onPause调用时不带Activity#onResume,还是Context#registerReceiver失败
更多参考资料:
从完全不同的方面来看,注销时的错误... Otto总线.. Quote:对我们来说,这仅出现在Samsung设备上.快速搜索后,...
More reference:
From quite a different aspect, Bug on unregister...Otto bus.. quote: For us, this only appears on Samsung devices. And after a quick search,...
如果需要更清晰的说明,请进行编辑,更正和改善答案.希望节省一些时间.
Please edit, correct, improve the answer if there's any more clarity to it.. hope it saves some time.
这篇关于Android接近传感器问题仅在Samsung设备中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!