是否有可能通过JavaScript来锁定Android上的方向? [英] Is it possible to lock the orientation on android through JavaScript?

查看:122
本文介绍了是否有可能通过JavaScript来锁定Android上的方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是,即使可能吗?我对此表示怀疑,但要确保。

Is that even possible? I doubt it, but want to make sure.

推荐答案

如果你不能写任何Java code来执行这个方向锁定,那么,不,这是不可能的锁定方向从JavaScript的应用程序。

If you're not allowed to write any Java code to perform this "orientation lock", then, no, it's not possible to lock the orientation of the app from JavaScript.

您可以模拟'锁定',如果你检测的方向变化在<一提到href=\"http://stackoverflow.com/questions/1649086/detect-rotation-of-android-phone-in-the-browser-with-javascript\">Detect在使用JavaScript的浏览器链接,并相应地调整你的HTML的Andr​​oid手机的旋转。但是,这似乎是一个大量的工作。

You could simulate 'locking' if you detected the orientation change as mentioned in the Detect rotation of Android phone in the browser with javascript link and readjusted your HTML accordingly. But that seems like a lot of work.

如果您可以使用Java,那么你可以通过公开的<一个Java对象href=\"http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface%28java.lang.Object,%20java.lang.String%29\"相对=nofollow> WebView.addJavascriptInterface 方法,写一些JavaScript获取/设置使用<一个方向href=\"http://developer.android.com/reference/android/app/Activity.html#setRequestedOrientation%28int%29\"相对=nofollow> Activity.setRequestedOrientation 和<一个href=\"http://developer.android.com/reference/android/app/Activity.html#getRequestedOrientation%28%29\"相对=nofollow> Activity.getRequestedOrientation 方法。

If you can use Java, then you can expose a Java object through the WebView.addJavascriptInterface method and write some JavaScript to get/set the orientation using the Activity.setRequestedOrientation and Activity.getRequestedOrientation methods.

这篇关于是否有可能通过JavaScript来锁定Android上的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆