我想檢查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
請試着給我們提供比'it given error'更多的細節。 –
@FD_抱歉沒有顯示logcat。但是現在我已經更新了我的問題。 – FAISAL
你並沒有掩蓋你的地圖API密鑰。 –