我正在创建一个应用程序,我将用户信息存储在用户驱动器隐藏的应用程序文件夹中。但是,当我尝试检索该信息时,它会给出一个例外。以下是我的示例代码,如果您有任何其他解决方案,请提供给我。在此先感谢
private void getDataFromDrive(){
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.build();
Drive.DriveApi.requestSync(mGoogleApiClient).setResultCallback(syncCallBack);
}
private ResultCallback<Status> syncCallBack = new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (!status.isSuccess()) {
if (DriveStatusCodes.DRIVE_RATE_LIMIT_EXCEEDED == status.getStatusCode()) {
//intimate user to wait for some time if you want to
}
}
//now query db file from google drive's app folder
queryMethod();
}
};
private void queryMethod() {
Query query = new Query.Builder()
.addFilter(Filters.eq(SearchableField.TITLE, "New file.txt"))
.build();
Task<MetadataBuffer> queryTask = getDriveResourceClient().query(query);
queryTask.addOnSuccessListener(this,
new OnSuccessListener<MetadataBuffer>() {
@Override
public void onSuccess(MetadataBuffer metadataBuffer) {
Log.e(TAG, "retrieving files");
showMessage(getString(R.string.query_pass));
finish();
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "---->Enter In Open File Fail");
Log.e(TAG, "Error retrieving files");
showMessage(getString(R.string.query_failed));
finish();
}
});
}
例外:
java.lang.IllegalStateException: GoogleApiClient is not connected yet.
at com.google.android.gms.common.api.internal.zzba.zze(Unknown Source)
at com.google.android.gms.internal.zzbls.requestSync(Unknown Source)
at com.cloudbackupdemo.BaseDemoActivity.getDataFromDrive(BaseDemoActivity.java:179)
at com.cloudbackupdemo.BaseDemoActivity.onClick(BaseDemoActivity.java:161)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)