Created
September 16, 2020 06:12
-
-
Save tolunayozturk/564ddf8bb657935a2ec1fa38c51029f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void queryFiles() { | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
try { | |
if (mAccessToken == null) { | |
Log.d(TAG, "need to sign in first"); | |
return; | |
} | |
String containers = ""; | |
String queryFile = "fileName = '" + et_searchFileName.getText() | |
+ "' and mimeType != 'application/vnd.huawei-apps.folder'"; | |
if (cb_isApplicationData.isChecked()) { | |
containers = "applicationData"; | |
queryFile = "'applicationData' in parentFolder and ".concat(queryFile); | |
} | |
Drive drive = buildDrive(); | |
Drive.Files.List request = drive.files().list(); | |
FileList files; | |
while (true) { | |
files = request | |
.setQueryParam(queryFile) | |
.setPageSize(10) | |
.setOrderBy("fileName") | |
.setFields("category,nextCursor,files(id,fileName,size)") | |
.setContainers(containers) | |
.execute(); | |
if (files == null || files.getFiles().size() > 0) { | |
break; | |
} | |
if (!StringUtils.isNullOrEmpty(files.getNextCursor())) { | |
request.setCursor(files.getNextCursor()); | |
} else { | |
break; | |
} | |
} | |
String text = ""; | |
if (files != null && files.getFiles().size() > 0) { | |
fileSearched = files.getFiles().get(0); | |
text = fileSearched.toString(); | |
} else { | |
text = "empty"; | |
} | |
final String finalText = text; | |
MainActivity.this.runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
tv_queryResult.setText(finalText); | |
} | |
}); | |
Log.d(TAG, "query success"); | |
} catch (Exception e) { | |
Log.d(TAG, "query error " + e.toString()); | |
} | |
} | |
}).start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment