我已在我的项目中实施GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener
(以及它的三个回调方法onConnected
,onConnectionSuspended
和& onConnectionFailed
), 但我无法引用Google Location API客户端!
我已尝试将参数更改为this
,volumeContentObserver.this
,甚至事先在变量中保留上下文并在API客户端的参数中引用它。
P.S。,这是完整的类声明:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationServices;
public class volumeContentObserver extends ContentObserver implements LocationListener,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
以下是问题代码:
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(c)
.addConnectionCallbacks(volumeContentObserver.this)
.addOnConnectionFailedListener(volumeContentObserver.this)
.addApi(LocationServices.API)
.build()
.connect();// Connecting the client
}
答案 0 :(得分:0)
您正在分配连接响应,如果您想要连接,则返回void到mConnectApiClient:
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(c)
.addConnectionCallbacks(volumeContentObserver.this) .addOnConnectionFailedListener(volumeContentObserver.this)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect()
}
答案 1 :(得分:0)
问题是您在结尾处调用了connect()
,而void
不是GoogleApiClient
的实例。
试试这个:
mGoogleApiClient = new GoogleApiClient.Builder(c)
.addConnectionCallbacks(volumeContentObserver.this)
.addOnConnectionFailedListener(volumeContentObserver.this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
答案 2 :(得分:0)
正如我所做的那样,你应该试试这段代码,希望这项工作适合你
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
在此之前你必须定义gooleAiClient.connect();在onStart metod。