android - Android API Google Drive“连接失败”
问题描述
我尝试在 Android 上使用 API Google Drive 但是,我遇到了无法解决的错误。
GoogleApiClient 连接失败:ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
公共类 GoogleDriveBackup 实现备份,GoogleApiClient.OnConnectionFailedListener { @Nullable private GoogleApiClient googleApiClient;
@Nullable
private WeakReference<Activity> activityRef;
@Override
public void init(@NonNull final Activity activity) {
this.activityRef = new WeakReference<>(activity);
googleApiClient = new GoogleApiClient.Builder(activity)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
// Do nothing
}
@Override
public void onConnectionSuspended(int i) {
}
})
.addOnConnectionFailedListener(this)
.build();
}
@Override
public GoogleApiClient getClient() {
return googleApiClient;
}
@Override
public void start() {
if (googleApiClient != null) {
googleApiClient.connect();
} else {
throw new IllegalStateException("You should call init before start");
}
}
@Override
public void stop() {
if (googleApiClient != null) {
googleApiClient.disconnect();
} else {
throw new IllegalStateException("You should call init before start");
}
}
@Override
public void onConnectionFailed(@NonNull final ConnectionResult result) {
Log.i("error", "GoogleApiClient connection failed: " + result.toString());
if (result.hasResolution() && activityRef != null && activityRef.get() != null) {
Activity a = activityRef.get();
// show the localized error dialog.
try {
result.startResolutionForResult(a, 1);
} catch (IntentSender.SendIntentException e) {
FirebaseCrash.log("Drive connection failed");
FirebaseCrash.report(e);
e.printStackTrace();
GoogleApiAvailability.getInstance().getErrorDialog(a, result.getErrorCode(), 0).show();
}
} else {
Log.d("error", "cannot resolve connection issue");
}
}
}
请帮忙
解决方案
推荐阅读
- scala - 初始化顺序在惰性 val 访问时抛出空指针
- angular - Angular 5 i18n 管道指令使用?
- matlab - 在matlab中打印后在填充网格中可见三角线
- node.js - Mongoose 没有与 Namecheap 共享主机节点 js 应用上的数据库建立连接
- android - setOnScrollChangeListener 在 NestedScrollView 中不起作用
- swift - 如何从 SKNode.children 数组访问 SKNode 子类方法?
- javascript - 将 materializecss 从 0.100.1 升级到 1.0.0 会导致多个 javascript 错误
- javascript - 如何获取javascript变量值?
- python - 在 FeedItemService 中使用 mutate 方法时出现 KeyError
- jquery - 如何在html5中自动播放视频