How can i replace type_orientation (is deprecated) for android 4.0.3?

你离开我真会死。 提交于 2019-11-30 07:51:10

问题


Hello I want to use the type type_orientation but it is deprecated for the android 4.0.3 . I use it for the augmented reality. I tried to find on the net but without success. My application works but my text inside stay in the same place! Here my code:

 @Override
    protected void onStart() {      
        super.onStart();
        sensorMngr = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        sensorLstr = createListener();
        sensorMngr.registerListener(sensorLstr, sensorMngr.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_UI);
    }

    @Override
    protected void onStop() {       
        super.onStop();
        sensorMngr = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        sensorMngr.unregisterListener(sensorLstr, sensorMngr.getDefaultSensor(Sensor.TYPE_ORIENTATION));        
    }

Everything it s good just this, i looked already on http://developer.android.com/reference/android/hardware/Sensor.html, but i can t understand (I m french and my english is not very perfect...) Thank you very much for your help!!!


回答1:


Here's a link to a blog with a solution. Essentially, you stop using the Orientation Sensor and use the Magnetic Field Sensor and Accelerometer Sensor(s) in tandem to get equivalent functionality. It's more work but it does allow you to continue to use a callback to handle orientation changes.



来源:https://stackoverflow.com/questions/15003787/how-can-i-replace-type-orientation-is-deprecated-for-android-4-0-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!