8

Well I'm trying to add a lock orientation button, but when I call

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);

the screen goes to normal portrait. What am I doing wrong?

public void onSensorChanged(SensorEvent event) {

    x = event.values[0];
    y = event.values[1];
    z = event.values[2];

    orientation.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (x > 5){
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            } else if (x < -5){
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            } else if (y > 5){
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            } else if (y < -5){
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            }
        }
    });
}
Rotary Heart
  • 1,899
  • 3
  • 29
  • 44
  • 1
    altough not exactly what you want, it has some interesting code snippets http://stackoverflow.com/questions/6599770/screen-orientation-lock – F43nd1r Mar 29 '16 at 15:03

1 Answers1

1

Well I solved it changing

android:targetSdkVersion="15"

to this

android:targetSdkVersion="11"

in the manifest, I don't really think that this was the problem, but now its working. Just wanted to post it in case anyone have the issue.

Rotary Heart
  • 1,899
  • 3
  • 29
  • 44