0

我对这个问题困惑了很多天。当我在模拟器 4.2.2 api 17 上运行它时,它显示:除非您更新 Google Play 服务,否则该应用程序不会运行。

我不知道该怎么做。我的代码列出:

显现:

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

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

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

 <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" />
<!--  The following two permissions are not required to use      Google Maps Android API v2,but     are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.example.demogooglemap.permission.MAPS_RECEIVE" />
 <uses-feature
    android:name="android.hardware.location"
    android:required="false" />
<uses-feature
    android:name="android.hardware.location.network"
    android:required="false" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
    android:name="android.hardware.wifi"
    android:required="false" />

<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" >

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


    <activity
        android:name="com.example.demogooglemap.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>
  </application>

 </manifest>

xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/header"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<fragment
    android:id="@+id/map"
    android:layout_below="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>`

活性: package com.example.demogooglemap ;

 import android.os.Bundle;
 import android.app.Activity;
 import android.support.v4.app.FragmentActivity;
 import android.view.Menu;

 public class MainActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    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;
}

  }

我还导入了 google-play-services_lib。

4

2 回答 2

0

您错误地处理了 Google Play 服务。你应该(我会说“必须”)检查它是否符合链接库的要求并相应地采取行动(使用自己的代码而不是我的 26354):

int errorCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext);
if( errorCode != ConnectionResult.SUCCESS ) {
    if( GooglePlayServicesUtil.isUserRecoverableError( errorCode ) ) {
        Dialog errorDialog = GooglePlayServicesUtil.
                    getErrorDialog(errorCode, this, 26354);
        if( errorDialog != null ) {
            errorDialog.show();
        } else {
               // open GooglePlayService app page in store:
               // https://play.google.com/store/apps/details?id=com.google.android.gms
    }
}

或在您的设备上打开此链接:https: //play.google.com/store/apps/details?id=com.google.android.gms

于 2013-11-13T11:17:05.323 回答
-1

通过转到 SDK Manager 将 Android api 版本更新为 19

在 Windows 的开始按钮中搜索,输入**SDK Manager**您将到达那里您将看到一些更新,安装该更新

SDK 管理器

于 2013-11-13T11:17:10.020 回答