FusedLocationProviderApi を使用してタブレットの位置データを取得しようとしていますが、アプリケーションを起動するたびにエラーが発生します
E/MainActivity﹕ 接続に失敗しました: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null}
このエラーの原因がわかりません。問題を引き起こしている可能性があると思われる、ある種のブランド外のタブレットを持っています。モデル番号: DL701Q、Android バージョン: 4.4.2、Google Play ビルド バージョン 4.9.13
これが私のアプリケーションコードです。問題を見つけようとしてテストしていたので、いくつかはコメントアウトされています。
package temp;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import java.text.DateFormat;
import java.util.Date;
public class MainActivity extends Activity implements LocationListener,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener{
Button bLogout;
ImageButton bLogData;
GPSTracker gps;
TextView etLabel;
UserLocalStore userLocalStore;
Location mCurrentLocation;
String mLastUpdateTime;
LocationRequest mLocationRequest;
GoogleApiClient mGoogleApiClient;
private static final String TAG = "MainActivity";
private static final long INTERVAL = 1000 * 10;
private static final long FATEST_INTERVAL = 1000 * 5;
private static Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e(TAG, "On Create . . . . .");
// if(!isGooglePlayServicesAvailable()){
// finish();
// }
createLocationRequest();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
etLabel = (TextView) findViewById(R.id.etEmailLabel);
bLogout = (Button) findViewById(R.id.bLogout);
bLogData = (ImageButton) findViewById(R.id.DataLog);
// gps = new GPSTracker(MainActivity.this);
bLogData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
updateUI();
}
});
bLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
userLocalStore.clearuserData();
userLocalStore.setUserLoggedIn(false);
startActivity(new Intent(MainActivity.this, login.class));
}
});
userLocalStore = new UserLocalStore(this);
}
protected void createLocationRequest(){
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(INTERVAL);
mLocationRequest.setFastestInterval(FATEST_INTERVAL);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
@Override
public void onStart() {
super.onStart();
if(authenticate() == true){
displayUserDetails();
}else{
startActivity(new Intent(MainActivity.this, login.class));
}
Log.e(TAG, "onStart fired ..............");
mGoogleApiClient.connect();
Log.e(TAG, "onStart fired .............." + mGoogleApiClient.isConnected());
}
@Override
public void onStop() {
super.onStop();
Log.e(TAG, "onStop fired ..............");
// mGoogleApiClient.disconnect();
Log.e(TAG, "isConnected ...............: " + mGoogleApiClient.isConnected());
}
private boolean isGooglePlayServicesAvailable() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (ConnectionResult.SUCCESS == status) {
return true;
} else {
GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
return false;
}
}
@Override
public void onConnected(Bundle bundle) {
Log.e(TAG, "onConnected - isConnected ...............: " + mGoogleApiClient.isConnected());
startLocationUpdates();
}
protected void startLocationUpdates() {
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
Log.e(TAG, "Location update started ..............: ");
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.e(TAG, "Connection failed: " + connectionResult.toString());
}
@Override
public void onLocationChanged(Location location) {
Log.e(TAG, "Firing onLocationChanged..............................................");
mCurrentLocation = location;
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
updateUI();
}
private void updateUI() {
Log.e(TAG, "UI update initiated .............");
if (null != mCurrentLocation) {
String lat = String.valueOf(mCurrentLocation.getLatitude());
String lng = String.valueOf(mCurrentLocation.getLongitude());
Toast.makeText(getApplicationContext(), "Longitude: " + lng + "\nLatitude: "
+ lat, Toast.LENGTH_LONG).show();
} else {
Log.e(TAG, "location is null ...............");
Toast.makeText(getApplicationContext(), "Location Null", Toast.LENGTH_LONG).show();
}
}
@Override
protected void onPause() {
super.onPause();
// stopLocationUpdates();
}
protected void stopLocationUpdates() {
// LocationServices.FusedLocationApi.removeLocationUpdates(
// mGoogleApiClient, this);
Log.e(TAG, "Location update stopped .......................");
}
@Override
public void onResume() {
super.onResume();
if (mGoogleApiClient.isConnected()) {
startLocationUpdates();
Log.e(TAG, "Location update resumed .....................");
}
}
private void displayUserDetails(){
User user = userLocalStore.getLoggedInUser();
String userdisplay = "Logged in as: " + user.username;
etLabel.setText(userdisplay);
}
private boolean authenticate(){
return userLocalStore.getUserLoggedIn();
}
}
マニフェスト ファイル
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="temp" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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>
<activity
android:name=".login"
android:label="@string/title_activity_login" >
</activity>
<activity
android:name=".Register"
android:label="@string/title_activity_register" >
</activity>
</application>
</manifest>
ビルドファイル
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "temp"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
}