PhoneGap / Android中的屏幕方向

时间:2012-08-20 12:00:49

标签: android cordova orientation

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

我现在的问题是,只要我想更改屏幕方向,它就会崩溃。即使我从onCreate方法尝试像setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);这样简单(在技术上不使用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概念?任何人都有线索?

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:0)