Android: allow portrait and landscape for tablets, but force portrait on phone? -


i tablets able display in portrait , landscape (sw600dp or greater), phones restricted portrait only. can't find way conditionally choose orientation. suggestions?

here's way using resources , size qualifiers.

put bool resource in res/values bools.xml or whatever (file names don't matter here):

    <?xml version="1.0" encoding="utf-8"?>     <resources>         <bool name="portrait_only">true</bool>     </resources> 

put 1 in res/values-sw600dp , res/values-xlarge:

    <?xml version="1.0" encoding="utf-8"?>     <resources>         <bool name="portrait_only">false</bool>     </resources> 

see this supplemental answer adding these directories , files in android studio.

then, in oncreate method of activities can this:

    if(getresources().getboolean(r.bool.portrait_only)){         setrequestedorientation(activityinfo.screen_orientation_portrait);     } 

devices more 600 dp in smallest width direction, or x-large on pre-android 3.2 devices (tablets, basically) behave normal, based on sensor , user-locked rotation, etc. else (phones, pretty much) portrait only.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -