Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android 4.3中来自android.hardware.SensorManager.registerListener的意外错误返回值_Android_Accelerometer_Sensors_Proximity_Proximitysensor - Fatal编程技术网

android 4.3中来自android.hardware.SensorManager.registerListener的意外错误返回值

android 4.3中来自android.hardware.SensorManager.registerListener的意外错误返回值,android,accelerometer,sensors,proximity,proximitysensor,Android,Accelerometer,Sensors,Proximity,Proximitysensor,使用LG Nexus 4、Android 4.3 返回值有时是错误的,我不明白为什么。文档说明:“如果支持并成功启用传感器,则为真。” 奇怪的是,我没有看到过测试SensorManager.registerListener返回值的示例 奇怪的是,如果我忽略返回一个假值,那么一切都会按预期工作 文件: android.hardware.SensorManager, android.hardware.SystemSensorManager 我的代码: SensorManager sensorMgr

使用LG Nexus 4、Android 4.3

返回值有时是错误的,我不明白为什么。文档说明:“如果支持并成功启用传感器,则为真。”

奇怪的是,我没有看到过测试SensorManager.registerListener返回值的示例

奇怪的是,如果我忽略返回一个假值,那么一切都会按预期工作

文件:

android.hardware.SensorManager, android.hardware.SystemSensorManager

我的代码:

SensorManager sensorMgr = (SensorManager)_context.getSystemService(Context.SENSOR_SERVICE);
if (sensorMgr == null) {
    Log.w(TAG, "200410::Sensors not supported");
    return false;
}

Sensor sensor = sensorMgr.getDefaultSensor(Sensor.TYPE_PROXIMITY);
result = sensorMgr.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
if( result == false) {
    // Normally something should be done here
    // since the false return value indicated that registration failed.
    // But I found it's better doing nothing since the registration seams to be ok
}
return result;
奇怪的错误返回值在Android 4.3之前没有出现过

因此,如果结果值没有像在所有示例中那样使用,那么一切都是好的。也许我应该对此感到满意,但我有三个问题:

  • 为什么这个返回值从未在示例中测试过
  • 为什么Android 4.3中的返回值为false
  • 为什么即使返回值为false,它也能工作
  • 我知道这些问题很难回答,但如果我得到其他人也有同样问题的信息,我会非常高兴

    我对Sensor.TYPE\u加速计和Sensor.TYPE\u接近度都有相同的行为