Android(Phonegap)在旋转时崩溃

时间:2012-10-03 10:44:17

标签: android cordova

我用Google搜索,一个活动元素需要PhoneGap的android:configChanges="orientation|screenSize|keyboardHidden"值来刷新屏幕尺寸。但是后来Eclipse认为存在错误:error: Error: String types not allowed (at 'configChanges' with value 'orientation|screenSize|keyboardHidden').。那么我的清单配置有什么问题?这是我的整个Android清单配置:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.agilitus"
    android:versionCode="1"
    android:versionName="1.0" android:installLocation="internalOnly">

    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
    />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />


    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:debuggable="true" android:testOnly="false">
        <activity
            android:name=".IndexActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="orientation|screenSize|keyboardHidden">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

如您所见,我安装了3.2以上的所有版本 My Android SDK Manager window

As you can see I installed all versions above 3.2仍然出错 My manifest file

2 个答案:

答案 0 :(得分:2)

试试这个,只需复制粘贴此代码。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.agilitus"
    android:versionCode="1"
    android:versionName="1.0" android:installLocation="internalOnly">

    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:resizeable="true"
        android:anyDensity="true"
    />

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />


    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:debuggable="true" android:testOnly="false">
        <activity
            android:name=".IndexActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|keyboardHidden" 
            android:screenOrientation="portrait">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

答案 1 :(得分:1)

尝试反转screenSize和keyboardHidden。

screenSize已经added in SDK版本13.如果您尝试在Android 3.1或更低版本上启动应用程序,则无法使用,因为SDK无法找到screenSize值。

顺便说一句,Phonegap starting guide建议使用configChanges的这个值:

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"