我收到此错误"不幸的是,我的地图停止了#34;每当我尝试运行此应用程序时,在我的手机上("我的地图"是应用程序的名称)。
我的google_services是第17版
有谁知道如何解决这个问题?
**解决方案:**经过2个令人沮丧的日子后,我找到了问题的解决方案:
所以它不足以将它作为应用程序标记的子项添加到清单文件中:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/app_key"/> //app_key is the value of my api key
你应该将整数初始化为4452000而不是4132500,正如我在另一篇文章中所说的那样。 (这可以添加到字符串文件夹中)
<integer name="google_play_services_version">4452000</integer>
MainActivity.java
package com.seminarion.shiran;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
android.view.Menu;
import android.widget.Toast;
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, "Ready to map!", 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;
}
//this method checking whether the google play kit services are installed in the device of the user and
//letting the user know his current status.
public boolean servicesOK() {
int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
//IF I get a value of success that's mean googlePlay services is installed
//and we can display a map
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
}
else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}
else {
//error which is not recoverd by the user . we simply show the user an error message
Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
}
return false;
}
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.seminarion.shiran"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.seminarion.shiran.permission.MAPS_RECEIVE"
protectionLevel="signature"/>
<uses-permission android:name="com.seminarion.shiran.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.provider.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.seminarion.shiran.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="Here is my key..." //API KEY
/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
logcat的:
05-27 12:54:46.205: D/AndroidRuntime(10437): Shutting down VM
05-27 12:54:46.205: W/dalvikvm(10437): threadid=1: thread exiting with uncaught exception (group=0x40ff4930)
05-27 12:54:46.205: E/AndroidRuntime(10437): FATAL EXCEPTION: main
05-27 12:54:46.205: E/AndroidRuntime(10437): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.seminarion.shiran/com.seminarion.shiran.MainActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4452000 but found 4132500. 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" />
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2296)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.app.ActivityThread.access$700(ActivityThread.java:151)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.os.Looper.loop(Looper.java:137)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.app.ActivityThread.main(ActivityThread.java:5293)
05-27 12:54:46.205: E/AndroidRuntime(10437): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 12:54:46.205: E/AndroidRuntime(10437): at java.lang.reflect.Method.invoke(Method.java:511)
05-27 12:54:46.205: E/AndroidRuntime(10437): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-27 12:54:46.205: E/AndroidRuntime(10437): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-27 12:54:46.205: E/AndroidRuntime(10437): at dalvik.system.NativeStart.main(Native Method)
05-27 12:54:46.205: E/AndroidRuntime(10437): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4452000 but found 4132500. 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" />
05-27 12:54:46.205: E/AndroidRuntime(10437): at com.google.android.gms.common.GooglePlayServicesUtil.t(Unknown Source)
05-27 12:54:46.205: E/AndroidRuntime(10437): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
05-27 12:54:46.205: E/AndroidRuntime(10437): at com.seminarion.shiran.MainActivity.servicesOK(MainActivity.java:40)
05-27 12:54:46.205: E/AndroidRuntime(10437): at com.seminarion.shiran.MainActivity.onCreate(MainActivity.java:23)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.app.Activity.performCreate(Activity.java:5250)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
05-27 12:54:46.205: E/AndroidRuntime(10437): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
05-27 12:54:46.205: E/AndroidRuntime(10437): ... 11 more
答案 0 :(得分:0)
不,你不应该自己设置google-play-version。它已在res / values / version.xml
下的google-play-service项目中指定尝试重新安装google-play-service(https://stackoverflow.com/a/24152276/1885518),或者只是通过SDK-Manager更新(如果尚未关闭)。