我已经为自己找到了解决方案。只需获取所有文件的列表,与查找文件进行比较,然后获取它的 ID。这是我的代码:
public List<DFile> getFileIdFromName(String fileName) {
DFile res = null;
// List<DFile> dolphinListFile = getListFile(DIR_HOME);
// for (DFile dolphin : dolphinListFile) {
// if (dolphin.getFileName().compareTo(fileName) == 0)
// res = dolphin;
// }
boolean canGetId = true;
if (!isLoggedIn()) {
OnGetIdFromFileNameChecked(null, "Not logged in or check session false");
canGetId = false;
}
if (canGetId) {
mFileList = new ArrayList<DFile>();
final String mFileName = fileName;
mClient.getAsync(DIR_HOME + "/files", new LiveOperationListener() {
@Override
public void onComplete(LiveOperation operation) {
JSONObject result = operation.getResult();
if (result.has(JsonKeys.ERROR)) {
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
String message = error.optString(JsonKeys.MESSAGE);
String code = error.optString(JsonKeys.CODE);
Log.d("Dolphin download err", code + ": " + message);
return;
}
JSONArray data = result.optJSONArray(JsonKeys.DATA);
for (int i = 0; i < data.length(); i++) {
SkyDriveObject skyDriveObj = SkyDriveObject.create(data.optJSONObject(i));
skyDriveObj.accept(new Visitor() {
@Override
public void visit(SkyDriveAlbum album) {
mDFile = new DFile(album.getId(), "N/A", album.getName(), DFile.FILEHOST_SKYDRIVE, DFile.FILETYPE_ALBUM);
}
@Override
public void visit(SkyDrivePhoto photo) {
mDFile = new DFile(photo.getId(), "N/A", photo.getName(), DFile.FILEHOST_SKYDRIVE, DFile.FILETYPE_PHOTO);
}
@Override
public void visit(SkyDriveFolder folder) {
mDFile = new DFile(folder.getId(), "N/A", folder.getName(), DFile.FILEHOST_SKYDRIVE, DFile.FILETYPE_FOLDER);
}
@Override
public void visit(SkyDriveFile file) {
mDFile = new DFile(file.getId(), "N/A", file.getName(), DFile.FILEHOST_SKYDRIVE, DFile.FILETYPE_FILE);
}
@Override
public void visit(SkyDriveVideo video) {
mDFile = new DFile(video.getId(), "N/A", video.getName(), DFile.FILEHOST_SKYDRIVE, DFile.FILETYPE_VIDEO);
}
@Override
public void visit(SkyDriveAudio audio) {
mDFile = new DFile(audio.getId(), "N/A", audio.getName(), DFile.FILEHOST_SKYDRIVE, DFile.FILETYPE_AUDIO);
}
});
if (mDFile.getFileName().compareTo(mFileName) == 0) {
mFileList.add(mDFile);
}
}
OnGetIdFromFileNameChecked(mFileList, "Complete");
}
@Override
public void onError(LiveOperationException exception, LiveOperation operation) {
Log.d("Dolphin download err", exception.getMessage());
OnGetListChecked(null, exception.getMessage());
}
});
}
return mFileList;
}