Android Studio上的Google API错误
问题描述:
我在Google Play服务库中遇到了一些问题。Android Studio上的Google API错误
我已经导入这些文件:
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
我得到的错误在整个项目的 “GoogleApiClient”: -
public class MainActivity extends FragmentActivity implements LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener
在这里我得到的错误与locationClient/LocationServices/GoogleApiClient
locationClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
这里是“locationClient”的错误
@Override
public void onStop() {
// If the client is connected
if (locationClient.isConnected()) {
stopPeriodicUpdates();
}
// After disconnect() is called, the client is considered "dead".
locationClient.disconnect();
super.onStop();
}
/*
* Called when the Activity is restarted, even before it becomes visible.
*/
@Override
public void onStart() {
super.onStart();
// Connect to the location services client
locationClient.connect();
}
在这里,我得到错误 “onConnectionSuspended”
@Override
public void onConnectionSuspended(int i) {
Log.i(Application.APPTAG, "GoogleApiClient connection has been suspend");
}
答
确保您已包括谷歌Play服务,在您的build.gradle的依赖,例如:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
}
+0
确保您拥有清单和sha1代码中的所有权限。 –
+1
@MohamedSalad是的,也需要这些,但没有设置这些不会导致编译错误,它会导致运行时错误。 –
记住:有一个错误?添加完整的logcat – piotrek1543