我正在尝试使用 servicesOK 方法检查我的应用程序中的Google Play商店服务可用性,但是因为元数据标记不包含正确值的意外错误而崩溃。
代码:
**protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(servicesOK()){
}
setContentView(R.layout.activity_home_screen);
}
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();
}
return false;
}**
的Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webmonopolists.project_linx"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:maxSdkVersion="17"
android:minSdkVersion="8"
android:targetSdkVersion="10" />
<permission
android:name="com.webmonopolists.project_linx.permission.MAPS_RECIEVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.webmonopolists.project_linx.permission.MAPS_RECIEVE" />
<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.webmonopolists.project_linx.HomeScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.webmonopolists.project_linx.Main_Activity" />
<activity
android:name="com.webmonopolists.project_linx.MainActivity"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name="com.webmonopolists.project_linx.SourceDestinationActivity"
android:label="@string/title_activity_source_destination" >
</activity>
<activity
android:name="com.webmonopolists.project_linx.Routemap"
android:label="@string/title_activity_routemap" >
</activity>
<activity
android:name="com.webmonopolists.project_linx.RouteSummary"
android:label="@string/title_activity_route_summary" >
</activity>
<activity
android:name="com.webmonopolists.project_linx.SavedRoutes"
android:label="@string/title_activity_saved_routes" >
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAmiJ6vLbgWGEtge0g_9Gwdn7xIymjl92c"
/>
</application>
</manifest>
日志数据:
01-02 04:43:06.781:E / AndroidRuntime(1521):致命异常:主
01-02 04:43:06.781:E / AndroidRuntime(1521):java.lang.RuntimeException:无法启动活动ComponentInfo {com.webmonopolists.project_linx / com.webmonopolists.project_linx.HomeScreen}:java.lang。 IllegalStateException:应用程序的AndroidManifest.xml中的元数据标记没有正确的值。预期7095000但找到0.您必须在元素中包含以下声明:
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1734)
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1753)
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.app.ActivityThread.access $ 1500(ActivityThread.java:155)
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:999)
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.os.Handler.dispatchMessage(Handler.java:130)
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.os.Looper.loop(SourceFile:351)
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.app.ActivityThread.main(ActivityThread.java:3820)
01-02 04:43:06.781:E / AndroidRuntime(1521):at java.lang.reflect.Method.invokeNative(Native Method)
01-02 04:43:06.781:E / AndroidRuntime(1521):at java.lang.reflect.Method.invoke(Method.java:538)
01-02 04:43:06.781:E / AndroidRuntime(1521):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:969)
01-02 04:43:06.781:E / AndroidRuntime(1521):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:727)
01-02 04:43:06.781:E / AndroidRuntime(1521):at dalvik.system.NativeStart.main(Native Method)
01-02 04:43:06.781:E / AndroidRuntime(1521):引起:java.lang.IllegalStateException:应用程序的AndroidManifest.xml中的元数据标签没有正确的值。预期7095000但找到0.您必须在元素中包含以下声明:
01-02 04:43:06.781:E / AndroidRuntime(1521):at com.google.android.gms.common.GooglePlayServicesUtil.zzJ(Unknown Source)
01-02 04:43:06.781:E / AndroidRuntime(1521):at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
01-02 04:43:06.781:E / AndroidRuntime(1521):at com.webmonopolists.project_linx.HomeScreen.servicesOK(HomeScreen.java:48)
01-02 04:43:06.781:E / AndroidRuntime(1521):at com.webmonopolists.project_linx.HomeScreen.onCreate(HomeScreen.java:21)
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
01-02 04:43:06.781:E / AndroidRuntime(1521):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1698)
01-02 04:43:06.781:E / AndroidRuntime(1521):... 11更多
答案 0 :(得分:4)
在现有<meta-data>
元素之后,添加另一个元素:
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
您可以在不到一年的任何Maps V2示例中找到此内容,包括this directory中的所有示例。