Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyAct extends Activity {
- private OrientationEventListener listener;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- listener = new OrientationEventListener(this,
- SensorManager.SENSOR_DELAY_UI) {
- @Override
- public void onOrientationChanged(int orientation) {
- Log.d("test", "orientation = " + orientation);
- if ((orientation >= 350 && orientation <= 360)
- || (orientation >= 0 && orientation <= 10)) {
- listener.disable();
- //Do what you need with the above conditions
- //Disable is optional, it "pauses" the listener
- }
- }
- };
- listener.enable();
- super.onCreate(savedInstanceState);
- }
- }
Add Comment
Please, Sign In to add comment