1

我目前正在PhoneGap 中开发一个小演示来测试一些功能。我想使用Github 提供的 PhoneGap-OrientationLock 插件,以便能够从 JavaScript 动态更改我的屏幕方向,我已经更新了插件以在 Cordova 中使用它。

我现在的问题是,一旦我想更改屏幕方向,它就会崩溃。即使我setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);从我的 onCreate 方法中尝试了一些简单的操作(在技术上不使用 PhoneGap),我的应用程序也会使用以下调试日志退出到启动器:

08-20 08:57:17.083: D/DroidGap(21383): DroidGap.onCreate()
08-20 08:57:17.193: D/CordovaWebView(21383): Origin to allow: http://127.0.0.1*
08-20 08:57:17.193: I/CordovaLog(21383): Found log level DEBUG
08-20 08:57:17.193: I/CordovaLog(21383): Changing log level to DEBUG(3)
08-20 08:57:17.193: I/CordovaLog(21383): Found preference for fullscreen=true
08-20 08:57:17.193: D/CordovaLog(21383): Found preference for fullscreen=true
08-20 08:57:17.193: I/CordovaLog(21383): Found preference for useBrowserHistory=false
08-20 08:57:17.193: D/CordovaLog(21383): Found preference for useBrowserHistory=false
08-20 08:57:17.223: D/DroidGap(21383): DroidGap.init()
08-20 08:57:17.223: D/CordovaWebView(21383): >>> loadUrl(file:///android_asset/www/index.html)
08-20 08:57:17.223: D/PluginManager(21383): init()
08-20 08:57:17.233: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:17.243: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:17.243: D/DroidGap(21383): onDestroy()
08-20 08:57:17.243: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:17.243: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:17.263: D/DroidGap(21383): DroidGap.onCreate()
08-20 08:57:17.263: D/CordovaWebView(21383): Origin to allow: http://127.0.0.1*
08-20 08:57:17.263: I/CordovaLog(21383): Found log level DEBUG
08-20 08:57:17.263: I/CordovaLog(21383): Changing log level to DEBUG(3)
08-20 08:57:17.263: I/CordovaLog(21383): Found preference for fullscreen=true
08-20 08:57:17.263: D/CordovaLog(21383): Found preference for fullscreen=true
08-20 08:57:17.263: I/CordovaLog(21383): Found preference for useBrowserHistory=false
08-20 08:57:17.263: D/CordovaLog(21383): Found preference for useBrowserHistory=false
08-20 08:57:17.273: D/DroidGap(21383): DroidGap.init()
08-20 08:57:17.273: D/CordovaWebView(21383): >>> loadUrl(file:///android_asset/www/index.html)
08-20 08:57:17.273: D/PluginManager(21383): init()
08-20 08:57:17.293: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:17.313: D/DroidGap(21383): onMessage(onPageStarted,file:///android_asset/www/index.html)
08-20 08:57:17.313: D/SoftKeyboardDetect(21383): Ignore this event
08-20 08:57:17.373: D/SoftKeyboardDetect(21383): Ignore this event
08-20 08:57:17.483: D/Cordova(21383): onPageFinished(file:///android_asset/www/index.html)
08-20 08:57:17.483: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:17.483: D/DroidGap(21383): onMessage(onNativeReady,null)
08-20 08:57:17.483: D/DroidGap(21383): onMessage(onPageFinished,file:///android_asset/www/index.html)
08-20 08:57:17.483: D/DroidGap(21383): onMessage(onPageStarted,about:blank)
08-20 08:57:17.503: D/dalvikvm(21383): GC_CONCURRENT freed 326K, 9% free 7566K/8263K, paused 8ms+2ms, total 33ms
08-20 08:57:17.513: D/Cordova(21383): onPageFinished(about:blank)
08-20 08:57:17.513: D/DroidGap(21383): onMessage(onPageFinished,about:blank)
08-20 08:57:17.513: D/DroidGap(21383): onMessage(exit,null)
08-20 08:57:17.563: D/DroidGap(21383): onMessage(onPageStarted,file:///android_asset/www/index.html)
08-20 08:57:17.563: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:18.023: D/Cordova(21383): onPageFinished(file:///android_asset/www/index.html)
08-20 08:57:18.023: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:18.023: D/DroidGap(21383): onMessage(onNativeReady,null)
08-20 08:57:18.023: D/DroidGap(21383): onMessage(onPageFinished,file:///android_asset/www/index.html)
08-20 08:57:18.053: E/SQLiteLog(21383): (14) cannot open file at line 30174 of [00bb9c9ce4]
08-20 08:57:18.053: E/SQLiteLog(21383): (14) os_unix.c:30174: (2) open(/CachedGeoposition.db) - 
08-20 08:57:18.053: D/WebKit(21383): ERROR: 
08-20 08:57:18.053: D/WebKit(21383): SQLite database failed to load from /CachedGeoposition.db
08-20 08:57:18.053: D/WebKit(21383): Cause - unable to open database file
08-20 08:57:18.053: D/WebKit(21383): external/webkit/Source/WebCore/platform/sql/SQLiteDatabase.cpp(71) : bool WebCore::SQLiteDatabase::open(const WTF::String&, bool)
08-20 08:57:18.143: D/DroidGap(21383): onMessage(networkconnection,wifi)
08-20 08:57:18.183: D/DroidGap(21383): onMessage(spinner,stop)
08-20 08:57:18.223: W/IInputConnectionWrapper(21383): showStatusIcon on inactive InputConnection
08-20 08:57:18.263: D/DroidGap(21383): onDestroy()
08-20 08:57:18.263: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:18.263: D/CordovaWebView(21383): >>> loadUrlNow()
08-20 08:57:18.283: D/DroidGap(21383): onMessage(onPageStarted,about:blank)
08-20 08:57:18.303: D/Cordova(21383): onPageFinished(about:blank)
08-20 08:57:18.303: D/DroidGap(21383): onMessage(onPageFinished,about:blank)
08-20 08:57:18.303: D/DroidGap(21383): onMessage(exit,null)
08-20 08:57:19.483: D/DroidGap(21383): onMessage(spinner,stop)
08-20 08:57:19.513: D/DroidGap(21383): onMessage(spinner,stop)
08-20 08:57:20.023: D/DroidGap(21383): onMessage(spinner,stop)

所以它看起来就像我这样调用 setRequestedOrientation :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    super.loadUrl("file:///android_asset/www/index.html");
}

我的应用程序调用 onDestroy 并返回到启动器。我只是不了解Android概念吗?有人有线索吗?

4

1 回答 1

5

您应该 在出现android:configChanges="orientation|keyboardHidden"的第一个中添加 Android Manifest <activity>。我有同样的问题,它也让我的应用程序崩溃了。

于 2012-09-20T17:14:29.460 回答