首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SERVICE_VERSION_UPDATE_REQUIRED

SERVICE_VERSION_UPDATE_REQUIRED
EN

Stack Overflow用户
提问于 2016-12-02 08:05:49
回答 2查看 3.4K关注 0票数 6

实际上,我正在构建一个需要用户位置的应用程序。但是我得到了SERVICE_VERSION_UPDATE_REQUIRED错误。以下是我的MainActivity.javaAndroidManifest.xml文件:

MainActivity.java

代码语言:javascript
运行
复制
TextView lat, lon;
private static final String TAG = MainActivity.class.getSimpleName();

private FusedLocationProviderApi locationProvider = LocationServices.FusedLocationApi;
private GoogleApiClient googleApiClient;
private LocationRequest locationRequest;
private double latitude, longitude;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    lat = (TextView) findViewById(R.id.lat);
    lon = (TextView) findViewById(R.id.lon);

    if (googleApiClient == null) {
        googleApiClient = new GoogleApiClient.Builder(this)
                .addApi(LocationServices.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();
    }

    locationRequest = new LocationRequest();
    locationRequest.setInterval(10000);
    locationRequest.setFastestInterval(1000);
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}

@Override
public void onConnected(@Nullable Bundle bundle) {
    requestLocationUpdates();
}

private void requestLocationUpdates() {
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    Log.d(TAG, connectionResult.toString());
}

@Override
public void onLocationChanged(Location location) {
    latitude = location.getLatitude();
    longitude = location.getLongitude();
    lat.setText("Latitude: " + String.valueOf(latitude));
    lon.setText("Longitude: " + String.valueOf(longitude));
}

@Override
protected void onStart() {
    super.onStart();
    googleApiClient.connect();
}

@Override
protected void onResume() {
    super.onResume();
    if (googleApiClient.isConnected()) {
        requestLocationUpdates();
    }
}

@Override
protected void onPause() {
    super.onPause();
    LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
}

@Override
protected void onStop() {
    super.onStop();
    googleApiClient.disconnect();
}

AndroidManifest.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.harshil.location">

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

下面是logcat说的话:

代码语言:javascript
运行
复制
D/MainActivity: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}

那么,如何解决这个问题呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-12-02 17:51:19

我通过在build.gradle中更改以下行来解决问题:

代码语言:javascript
运行
复制
compile 'com.google.android.gms:play-services:10.0.1'

至:

代码语言:javascript
运行
复制
compile 'com.google.android.gms:play-services:9.8.0'

因此,问题在于我使用的是高级版本的Google服务,而不是安装在my device或模拟器上的。

我提出的解决办法如下:

1.我在我的设备上检查了更新Google服务,但是它说它是最新的。

2. --我在应用程序管理器中查看了它的版本,我知道它实际上是9.8.77。因此,我将play服务版本从10.0.1改为9.8.0。

现在,我解决了这个问题。

谢谢你,

票数 4
EN

Stack Overflow用户

发布于 2017-02-17 09:55:02

下载你的手机中的google商店,并检查它,.for me --我没有安装google商店,现在我安装了google商店,它正常工作。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40927420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档