开发者

SensorManager.registerListener wants a SensorListener despite its depreciation

@Override
protected void onResume(){
     //super.onResume();
        sensorManager.registerListener((SensorListener) listener,
                SensorManager.SENSOR_ACCELEROMETER
                |SensorManager.SENSOR_ORIENTATION,
                SensorManager.SENSOR_DELAY_NORMAL);
}

private SensorEventListener listener=new SensorEventListener() {
    public void onSensorChanged(SensorEvent event){
        if(event.sensor.getType() == Sensor.TYPE_ORIENTATION){
            System.out.println(event.values[0]);
        }
    }

    public void onAccuracyChanged(Sensor sensor, int accuracy){

    }
};

So the SensorManager.registerListener is where I'm having the issue. Eclipse insists on a SensorListener, and then proceeds to whine when I pass it one because SensorListener is depreciated. I can't seem to get this worked out and would really appreciate some input! I read the previous post and followed the instructions there to no avail. Thank开发者_开发知识库 you all very much!

Brad


I was having the same problem earlier. For me it was a simple fix. I updated to the latest SDK and ADT and simply swapped out the SensorListener with a SensorEventListener

sensorManager.registerListener(sensorEventListener, sensorManager.getDefaultSensor(Sensor.TYPE_OREINTATION), SensorManager.SENSOR_DELAY_NORMAL);

Works perfectly for me.


As suggested on this post: android SensorEventListener problem take a look at the code here: Commonsware compass demo

I'm stuck on the same thing and it's helping me out

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜