如何打开 DriveFolder (Api Google-Drive) 中的内容?
How to open content from a DriveFolder (Api Google-Drive)?
我问这个问题是因为我在打开 Google 中的文件夹的内容时遇到问题,我希望能够打开它的内容以获取数据并将它们复制到另一个文件夹.但是我用的方法报错不知道这个方法是不是只针对文件
我当前的代码只打开文件的内容,因为我已经评论过,我在这里出错了:
private void readFile(DriveId fileDriveId) {
DriveFile file = fileDriveId.asDriveFile();
file.open(apiClient, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.e(LOGTAG,"Error");
return;
}
DriveContents contents = result.getDriveContents();
BufferedReader reader =
new BufferedReader(
new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
try {
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (IOException e) {
Log.e(LOGTAG,"Error");
}
contents.discard(apiClient);
Log.i(LOGTAG, "YES": " + builder.toString());
}
});
}
如果他们注意到他们失败的地方或知道是否有其他方法可以实现目标。请评论。
如果您在获取驱动器 API 中的文件夹内容时遇到问题,那么您可以尝试检查此 Search a folder's contents. Also, it is stated here, that folder contents can be queried using [DriveFolder.queryChildren
](https://developers.google.com/android/reference/com/google/android/gms/drive/DriveFolder#queryChildren(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.drive.query.Query))。
有关详细信息,您可以查看此 documentation 如何使用文件内容。
我问这个问题是因为我在打开 Google 中的文件夹的内容时遇到问题,我希望能够打开它的内容以获取数据并将它们复制到另一个文件夹.但是我用的方法报错不知道这个方法是不是只针对文件
我当前的代码只打开文件的内容,因为我已经评论过,我在这里出错了:
private void readFile(DriveId fileDriveId) {
DriveFile file = fileDriveId.asDriveFile();
file.open(apiClient, DriveFile.MODE_READ_ONLY, null)
.setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.e(LOGTAG,"Error");
return;
}
DriveContents contents = result.getDriveContents();
BufferedReader reader =
new BufferedReader(
new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
try {
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (IOException e) {
Log.e(LOGTAG,"Error");
}
contents.discard(apiClient);
Log.i(LOGTAG, "YES": " + builder.toString());
}
}); }
如果他们注意到他们失败的地方或知道是否有其他方法可以实现目标。请评论。
如果您在获取驱动器 API 中的文件夹内容时遇到问题,那么您可以尝试检查此 Search a folder's contents. Also, it is stated here, that folder contents can be queried using [DriveFolder.queryChildren
](https://developers.google.com/android/reference/com/google/android/gms/drive/DriveFolder#queryChildren(com.google.android.gms.common.api.GoogleApiClient, com.google.android.gms.drive.query.Query))。
有关详细信息,您可以查看此 documentation 如何使用文件内容。