gpt4 book ai didi

android - 丢失 Google 云端硬盘中的文件内容

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:15:03 26 4
gpt4 key购买 nike

这是一个很奇怪的现象。我的应用程序使用 Android Google Drive SDK 为每个用户存储两个数据文件。这些文件位于应用程序文件夹中。要连接到 Google 服务,我使用:

PlusOptions plusOptions = new Plus.PlusOptions.Builder()
.addActivityTypes("http://schemas.google.com/AddActivity").build();
mGoogleApi = new GoogleApiClient.Builder(this).addApi(Plus.API, plusOptions).addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE).addApi(Drive.API).addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER).addConnectionCallbacks(this).addOnConnectionFailedListener(this)
.build();

我能够创建并写入这些文件。但时不时地,这两个文件会消失,它们的内容也会丢失。logcat 流包含如下消息:

05-16 10:15:18.316: W/GLSUser(829): [apk][apk] Permission for debut.kholle to access oauth2:https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.appdata https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me will be managed remotely.
05-16 10:15:18.416: I/qtaguid(14877): Failed write_ctrl(u 56) res=-1 errno=22
05-16 10:15:18.416: I/qtaguid(14877): Untagging socket 56 failed errno=-22
05-16 10:15:18.416: W/NetworkManagementSocketTagger(14877): untagSocket(56) failed with errno -22
05-16 10:15:18.416: I/imp(14877): I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
05-16 10:15:18.416: I/imp(14877): Retrying request
05-16 10:15:18.436: W/GLSUser(829): [apk][apk] Permission for debut.kholle to access oauth2:https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.appdata https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me will be managed remotely.
05-16 10:15:18.516: W/GLSUser(829): GoogleAccountDataService.getToken()
05-16 10:15:18.546: I/qtaguid(21108): Failed write_ctrl(u 85) res=-1 errno=22
05-16 10:15:18.546: I/qtaguid(21108): Untagging socket 85 failed errno=-22
05-16 10:15:18.546: W/NetworkManagementSocketTagger(21108): untagSocket(85) failed with errno -22
05-16 10:15:18.546: I/imp(21108): I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
05-16 10:15:18.546: I/imp(21108): Retrying request
05-16 10:15:19.576: E/SyncSchedulerImpl(14877): Ignoring sync request: rate limited (on connection limit)

编辑:

这是我读取包含应用程序数据的文件的代码。此代码包含在 Activity onCreate 过程中:

monGoogleApiLire = new GoogleApiClient.Builder(this).addApi(Drive.API).addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {

@Override
public void onConnected(Bundle connectionHint) {
Filter titreFilter = Filters.eq(SearchableField.TITLE, NOM_FICHIER_PLANNING);
Query query = new Query.Builder().addFilter(titreFilter).build();
Drive.DriveApi.getAppFolder(monGoogleApiLire).queryChildren(monGoogleApiLire, query)
.setResultCallback(new ResultCallback<MetadataBufferResult>() {

@Override
public void onResult(MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
// showMessage("Error while trying to create the file");
return;
}
MetadataBuffer meta = result.getMetadataBuffer();
if (meta.getCount() != 0) {
int nb = meta.getCount();
DriveId idc = null;
for (int i = 0; i < nb; i++) {
idc = meta.get(i).getDriveId();
}
DriveFile fichier = Drive.DriveApi.getFile(monGoogleApiLire, idc);
fichier.openContents(monGoogleApiLire, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(new ResultCallback<ContentsResult>() {
@Override
public void onResult(ContentsResult result) {
if (!result.getStatus().isSuccess()) {
// display an error saying file can't be opened
return;
}
// Contents object contains pointers
// to the actual byte stream
Contents contents = result.getContents();
BufferedReader reader = new BufferedReader(
new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
String contentsAsString = builder.toString();
reader.close();

}

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
contents.close();
// fichier.commitAndCloseContents(gapi, contents);
}
});
} else {
monPlanning = new ArrayList<DonneesPlanning>();
afficherPlanning();
if (monPlanning != null && mesCours != null && mesLieux != null) {
ActiviteKholle.this.setProgressBarIndeterminateVisibility(false);
monGoogleApiLire.disconnect();
}
// monGoogleApiLire.disconnect();
}
meta.close();
}

});
titreFilter = Filters.eq(SearchableField.TITLE, NOM_FICHIER_COURS);
query = new Query.Builder().addFilter(titreFilter).build();
Drive.DriveApi.getAppFolder(monGoogleApiLire).queryChildren(monGoogleApiLire, query)
.setResultCallback(new ResultCallback<MetadataBufferResult>() {

@Override
public void onResult(MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
// showMessage("Error while trying to create the file");
return;
}
MetadataBuffer meta = result.getMetadataBuffer();
if (meta.getCount() != 0) {
int nb = meta.getCount();
DriveId idc = null;
for (int i = 0; i < nb; i++) {
idc = meta.get(i).getDriveId();
}
DriveFile fichier = Drive.DriveApi.getFile(monGoogleApiLire, idc);
fichier.openContents(monGoogleApiLire, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(new ResultCallback<ContentsResult>() {
@Override
public void onResult(ContentsResult result) {
if (!result.getStatus().isSuccess()) {
// display an error saying file can't be opened
return;
}
// Contents object contains pointers
// to the actual byte stream
Contents contents = result.getContents();
BufferedReader reader = new BufferedReader(
new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
String contentsAsString = builder.toString();
reader.close();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
contents.close();
// fichier.commitAndCloseContents(gapi, contents);
}
});
} else {
mesCours = new ArrayList<DonneesCours>();
if (monPlanning != null && mesCours != null && mesLieux != null) {
ActiviteKholle.this.setProgressBarIndeterminateVisibility(false);
monGoogleApiLire.disconnect();
}
}
meta.close();
}

});
titreFilter = Filters.eq(SearchableField.TITLE, NOM_FICHIER_LIEUX);
query = new Query.Builder().addFilter(titreFilter).build();
Drive.DriveApi.getAppFolder(monGoogleApiLire).queryChildren(monGoogleApiLire, query)
.setResultCallback(new ResultCallback<MetadataBufferResult>() {

@Override
public void onResult(MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
// showMessage("Error while trying to create the file");
return;
}
MetadataBuffer meta = result.getMetadataBuffer();
if (meta.getCount() != 0) {
int nb = meta.getCount();
DriveId idc = null;
for (int i = 0; i < nb; i++) {
idc = meta.get(i).getDriveId();
}
DriveFile fichier = Drive.DriveApi.getFile(monGoogleApiLire, idc);
fichier.openContents(monGoogleApiLire, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(new ResultCallback<ContentsResult>() {
@Override
public void onResult(ContentsResult result) {
if (!result.getStatus().isSuccess()) {
// display an error saying file can't be opened
return;
}
// Contents object contains pointers
// to the actual byte stream
Contents contents = result.getContents();
BufferedReader reader = new BufferedReader(
new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
String contentsAsString = builder.toString();
reader.close();

if (monPlanning != null && mesCours != null
&& mesLieux != null) {
ActiviteKholle.this
.setProgressBarIndeterminateVisibility(false);
monGoogleApiLire.disconnect();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
contents.close();
// fichier.commitAndCloseContents(gapi, contents);
}
});
} else {
mesLieux = new ArrayList<DonneesLieu>();
if (monPlanning != null && mesCours != null && mesLieux != null) {
ActiviteKholle.this.setProgressBarIndeterminateVisibility(false);
monGoogleApiLire.disconnect();
}
}
meta.close();
}

});
}

@Override
public void onConnectionSuspended(int cause) {
// TODO Auto-generated method stub

}

}).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {

@Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub

}

}).build();


monGoogleApiLire.connect();

这有解释吗?

附言: 经过大量的试验和测试,我现在确定在测试文件存在时字段“monGoogleApi”已连接。当我使用“queryChildren”按名称和 MIME 类型搜索文件时,在代码行中:

if (meta.getCount() != 0) {
...
}

在 15 分钟内,meta.getCount 等于 1,15 分钟后,meta.getCount 等于 0。

最佳答案

你检查过“monGoogleApi”的连接状态了吗?

此连接可能有 session 超时。

https://developer.android.com/reference/com/google/android/gms/common/api/GoogleApiClient.html#isConnected()

关于android - 丢失 Google 云端硬盘中的文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23698160/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com