SERVICE_VERSION_UPDATE_REQUIRED

时间:2016-12-02 08:05:50

标签: java android xml

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

MainActivity.java

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

<?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所说的:

D/MainActivity: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}

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

2 个答案:

答案 0 :(得分:5)

我通过更改以下行[在 build.gradle ]解决了我的问题:

// GetMapping and PostMapping for editing items in lists.
    @GetMapping("/ListsofLists/{id}/add")
    public String listItemAdd(Model model, @PathVariable(name = "id") int id) {
        model.addAttribute("id", id);
        ListItem u = listItemRepo.findOne(id);
        model.addAttribute("list_items", u);
        return "list_item_add";
    }

    @PostMapping("/ListsofLists/{id}/add")
    public String listItemSave(@ModelAttribute @Valid ListItem listItem, BindingResult result, Model model) {
        listItemRepo.save(listItem);
        return "redirect:/ListsofLists/{id}";
    }

为:

compile 'com.google.android.gms:play-services:10.0.1'

所以,问题是我使用更高版本 Google Play服务进行开发,而不是我的设备上安装的更高版本仿真器

我的解决方案如下:
1。我检查了我的设备上的 Google Play服务,但它说它是最新的
2。我检查了应用管理器以查看其版本,我发现它实际上是9.8.77。所以我将播放服务版本从 10.0.1 更改为 9.8.0
现在,我摆脱了这个问题。

谢谢。

答案 1 :(得分:-2)

在您的手机中下载谷歌游戏商店并检查它。对于我,我的手机中没有安装谷歌游戏商店,我现在安装谷歌游戏商店,它的工作正常。