我试图在服务中实现GoogleApiClient
。
public class SGoogle extends Service implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
//...
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
setConnected(false);
if (!result.hasResolution()) {
// show the localized error dialog.
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, 0).show();
return;
}
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}
}
但是很明显,需要使用Activity
来执行功能:
GooglePlayServicesUtil.getErrorDialog
和result.startResolutionForResult
。有没有办法避免这种互动?或者可能是一些示例,以避免使用Activity
来与服务的连接进行交互?有人解决了这个问题吗?