简体   繁体   中英

Lock and unlock orientation in phonegap

I want to enable and disable changes in orientation using phonegap.

For android there is the java call,

activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

but I was looking for something that was cross-platform, there is also the config.xml

<preference name="orientation" value="portrait"/>

but this is a global setting.

Any suggestions?

for cross platform in android add this line for portrait mode

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

and this one is for landscape

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

just after this line

super.onCreate(savedInstanceState); in your onCreate method,this solution is for android as i have not worked in ios i can not help you on it.

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