Search in sources :

Example 1 with Files

use of com.google.api.services.drive.Drive.Files in project keepass2android by PhilippC.

the class GoogleDriveFileStorage method listFiles.

@Override
public List<FileEntry> listFiles(String parentPath) throws Exception {
    GDrivePath gdrivePath = new GDrivePath(parentPath);
    String parentId = gdrivePath.getGDriveId();
    List<FileEntry> result = new ArrayList<FileEntry>();
    Drive driveService = getDriveService(gdrivePath.getAccount());
    try {
        if (driveService.files().get(parentId).execute().getLabels().getTrashed())
            throw new FileNotFoundException(parentPath + " is trashed!");
        logDebug("listing files in " + parentId);
        Files.List request = driveService.files().list().setQ("trashed=false and '" + parentId + "' in parents");
        do {
            try {
                FileList files = request.execute();
                for (File file : files.getItems()) {
                    String path = new GDrivePath(parentPath, file).getFullPath();
                    logDebug("listing file " + path);
                    FileEntry e = convertToFileEntry(file, path);
                    result.add(e);
                }
                request.setPageToken(files.getNextPageToken());
            } catch (IOException e) {
                System.out.println("An error occurred: " + e);
                request.setPageToken(null);
                throw e;
            }
        } while (request.getPageToken() != null && request.getPageToken().length() > 0);
    } catch (Exception e) {
        throw convertException(e);
    }
    return result;
}
Also used : FileList(com.google.api.services.drive.model.FileList) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) UserRecoverableAuthIOException(com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException) IOException(java.io.IOException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) UserRecoverableAuthIOException(com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Drive(com.google.api.services.drive.Drive) Files(com.google.api.services.drive.Drive.Files) File(com.google.api.services.drive.model.File)

Example 2 with Files

use of com.google.api.services.drive.Drive.Files in project Aegis by Decad3nce.

the class BackupGoogleAccountsActivity method getAegisFolder.

private static String getAegisFolder() {
    Files.List request = null;
    String folderID = null;
    try {
        request = service.files().list().setQ("mimeType= 'application/vnd.google-apps.folder' and title = 'aeGis Backup' and trashed = false");
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    do {
        FileList files;
        try {
            files = request.execute();
            for (File file : files.getItems()) {
                folderID = file.getId();
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    } while (request.getPageToken() != null && request.getPageToken().length() > 0);
    // Log.i(TAG, "FolderID: " + folderID);
    return folderID;
}
Also used : FileList(com.google.api.services.drive.model.FileList) UserRecoverableAuthIOException(com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException) IOException(java.io.IOException) Files(com.google.api.services.drive.Drive.Files) File(com.google.api.services.drive.model.File)

Aggregations

UserRecoverableAuthIOException (com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)2 Files (com.google.api.services.drive.Drive.Files)2 File (com.google.api.services.drive.model.File)2 FileList (com.google.api.services.drive.model.FileList)2 IOException (java.io.IOException)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Drive (com.google.api.services.drive.Drive)1 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1