请参阅我的MainActivity.java
并告诉我为什么会出现以下错误
The method addConnectionCallbacks(GoogleApiClient.ConnectionCallbacks) in the type GoogleApiClient.Builder is not applicable for the arguments (MainActivity)
package com.example.myapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
public class MainActivity extends Activity {
private GoogleApiClient mGoogleApiClient ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
buildGoogleApiClient();
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
}
请告诉我为什么会这样。 我是否必须添加任何导入?我从developer.android.com
获得了此代码答案 0 :(得分:7)
您的// a bit of HTML
function getAuctionUpdate() {
setTimeout(function () {
$.ajax({
type: "POST",
url: "{!! url('auction/live/update')!!}",
dataType: 'json',
data: {
auctionID: $('#auctionID').val()
},
success: function (data) {
if (data['success']) {
// Updates some labels, etc.
getAuctionUpdate(); // Rearms itself
}
}
} }); // Not sure if all brackets are correct in this snippet but they are 100% on real code
}, 5000);
需要实现接口MainActivity
和ConnectionCallbacks
。之后,您需要添加方法OnConnectionFailedListener
,onConnected
和onConnectionSuspended
:
onConnectionFailed