How to disable only Reverse screen orientations in android activity -


is there way disable reverse landscape , reverse portrait orientations in android activity. used below code.but reverse landscape coming on that.

     rotation = ((windowmanager) getsystemservice(window_service)).getdefaultdisplay().getrotation();      system.out.println("rotation value : " +rotation);     if(rotation==0){         system.out.println("portrait");          setrequestedorientation(activityinfo.screen_orientation_portrait);}     if(rotation==1){         system.out.println("landscape");          setrequestedorientation(activityinfo.screen_orientation_landscape);}       if(rotation==2 )      {          system.out.println("reverse portrait");          setrequestedorientation(activityinfo.screen_orientation_locked);      }      if(rotation==3)      {          system.out.println("reverse landscape");          setrequestedorientation(activityinfo.screen_orientation_locked);      } 

add android:configchanges="keyboardhidden|orientation" androidmanifest.xml. tells system configuration changes going handle yourself, in case doing nothing.

<activity android:name="mainactivity" android:screenorientation="portrait" //this line if want lock screen orientation android:configchanges="keyboardhidden|orientation|screensize"> 

check http://developer.android.com/reference/android/r.attr.html#configchanges more details.

then override onconfigurationchanged : http://developer.android.com/guide/topics/resources/runtime-changes.html

    @override     public void onconfigurationchanged(configuration newconfig) {         super.onconfigurationchanged(newconfig);          // checks orientation of screen         if (newconfig.orientation == configuration.orientation_landscape) {             toast.maketext(this, "landscape", toast.length_short).show();         } else if (newconfig.orientation == configuration.orientation_portrait){             toast.maketext(this, "portrait", toast.length_short).show();         }     } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -