简体   繁体   中英

Phonegap on Android. Can a lock screen orientation for a specific device size?

I am trying to lock the orientation for my Phonegap application on Android devices but only for small screens, ie telephones. On phones I would like to have only portrait but on tablet I would like both orientations available.

I am able to make the lock work in the manifest file but this is a global setting and I would prefer not to have to build 2 APK files to distribute, one for each device size.

Is this at all possible in the manifest file or do I need to add some code. If so where and what :-)

Thanks

Dave

Inside your MainActivity, capture what is the screen resolution using below code

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels; //240
int height = dm.heightPixels; //320

Then make a conditional statement for small screen and inside the condition add the below codes as you desire

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

OR

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM