gpt4 book ai didi

javascript - 用于更改屏幕方向的 phonegap 插件出错

转载 作者:行者123 更新时间:2023-11-29 22:02:30 25 4
gpt4 key购买 nike

我遇到了这个错误。

Uncaught TypeError: Object # has no method 'exec' at file:///android_asset/www/JS/pg-plugin-screen-orientation.js:4

var screenOrientation = function() {}

screenOrientation.prototype.set = function(str, success, fail) {

PhoneGap.exec(success, fail, "ScreenOrientation", "set", [str]); // GETTING ERROR IN THIS LINE

};

navigator.screenOrientation = new screenOrientation();

我已按照本文档中给出的步骤进行操作。 https://github.com/champierre/pg-plugin-screen-orientation


现在它工作正常。但是当这条线被执行时应用程序崩溃了

activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

07-24 18:01:19.200: E/AndroidRuntime(12001): FATAL EXCEPTION: main
07-24 18:01:19.200: E/AndroidRuntime(12001): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@4054e820 is not valid; is your activity running?
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.view.ViewRoot.setView(ViewRoot.java:527)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.view.Window$LocalWindowManager.addView(Window.java:424)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.app.Dialog.show(Dialog.java:241)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
07-24 18:01:19.200: E/AndroidRuntime(12001): at org.apache.cordova.Notification$1.run(Notification.java:205)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.app.Activity.runOnUiThread(Activity.java:3717)
07-24 18:01:19.200: E/AndroidRuntime(12001): at org.apache.cordova.Notification.alert(Notification.java:208)
07-24 18:01:19.200: E/AndroidRuntime(12001): at org.apache.cordova.Notification.execute(Notification.java:70)
07-24 18:01:19.200: E/AndroidRuntime(12001): at org.apache.cordova.api.PluginManager.exec(PluginManager.java:212)
07-24 18:01:19.200: E/AndroidRuntime(12001): at org.apache.cordova.CordovaChromeClient.onJsPrompt(CordovaChromeClient.java:185)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:566)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.os.Looper.loop(Looper.java:123)
07-24 18:01:19.200: E/AndroidRuntime(12001): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-24 18:01:19.200: E/AndroidRuntime(12001): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 18:01:19.200: E/AndroidRuntime(12001): at java.lang.reflect.Method.invoke(Method.java:507)
07-24 18:01:19.200: E/AndroidRuntime(12001): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-24 18:01:19.200: E/AndroidRuntime(12001): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-24 18:01:19.200: E/AndroidRuntime(12001): at dalvik.system.NativeStart.main(Native Method)

最佳答案

您使用的是什么版本的 PhoneGap/Cordova? PhoneGap 对象在最新版本中已重命名为 cordova。因此,您可能需要更新 JS 文件以调用 cordova.exec 而不是 PhoneGap.exec

关于javascript - 用于更改屏幕方向的 phonegap 插件出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11607510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com