谷歌播放服务

时间:2014-02-16 14:24:53

标签: android google-maps android-manifest google-play-services

我正在尝试检查google play services,但它会出错。 这是我的清单文件。

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

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

    <permission 
        android:name="com.example.gmapapp.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

    <uses-permission android:name="com.example.gmapapp.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission
        android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-feature 
        android:glEsVersion="0x00020000"
        android:required="true"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.gmapapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <meta-data 
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="GOOGLE_API_KEY"/>

    </application>

</manifest>

这是我的主要活动。

public class MainActivity extends Activity {

    private static final int GPS_ERRORDIALOG_REQUEST = 9001;
    GoogleMap mMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (servicesOK()) {
            Toast.makeText(this, "Google play services successfully connected.", Toast.LENGTH_SHORT).show();
        }
        setContentView(R.layout.activity_main);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public boolean servicesOK(){
        int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if (isAvailable == ConnectionResult.SUCCESS) {
            return true;
        }else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
            dialog.show();
        }else{
            Toast.makeText(this, "Can't connect to google play services.", Toast.LENGTH_SHORT).show();
        }
        return false;
    }

}

我的日志cat错误

02-15 19:22:58.070: E/AndroidRuntime(7499): FATAL EXCEPTION: main
02-15 19:22:58.070: E/AndroidRuntime(7499): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gmapapp/com.example.gmapapp.MainActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.os.Looper.loop(Looper.java:137)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.app.ActivityThread.main(ActivityThread.java:4424)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at java.lang.reflect.Method.invokeNative(Native Method)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at java.lang.reflect.Method.invoke(Method.java:511)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at dalvik.system.NativeStart.main(Native Method)
02-15 19:22:58.070: E/AndroidRuntime(7499): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 4242000 but found 0.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
02-15 19:22:58.070: E/AndroidRuntime(7499):     at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at com.example.gmapapp.MainActivity.servicesOK(MainActivity.java:36)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at com.example.gmapapp.MainActivity.onCreate(MainActivity.java:21)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.app.Activity.performCreate(Activity.java:4465)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-15 19:22:58.070: E/AndroidRuntime(7499):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-15 19:22:58.070: E/AndroidRuntime(7499):     ... 11 more

2 个答案:

答案 0 :(得分:8)

将以下内容添加到AndroidManifest.xml标记内的<application>

<meta-data android:name="com.google.android.gms.version" 
           android:value="@integer/google_play_services_version" />

日志实际上非常明确。

答案 1 :(得分:0)

你的日志猫只清楚地说:

  

java.lang.IllegalStateException:应用程序的AndroidManifest.xml中的元数据标记没有正确的值。预期4242000但找到0.您必须在application元素中包含以下声明:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

所以你只需将它添加到Android清单中的application元素中。