2014-02-16 201 views
0

我想检查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; 
    } 

} 

我的日志猫错误

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 
+1

请试着给我们提供比'it given error'更多的细节。 –

+0

@FD_抱歉没有显示logcat。但是现在我已经更新了我的问题。 – FAISAL

+0

你并没有掩盖你的地图API密钥。 –

回答

8

以下添加到您的AndroidManifest.xml,在<application>标签内:

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

日志其实是相当自明。

+0

@ integer/google_play_services_version有什么价值?我在哪里找到它? – Ale

+0

按住Ctrl并点击@ integer/google_play_services_version。 IDE将带你到资源被定义的地方。 (假设你正在使用Eclipse) –

+0

我没有得到该值..可能是因为我没有正确链接google_play_services库 – Ale

0

你的日志猫只清楚地说:

java.lang.IllegalStateException:在你的应用的AndroidManifest.xml的元数据标签没有正确的价值。预计4242000但发现0您必须应用元素中的如下声明:

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

所以你只需要添加它在应用元素的Android清单。