Android Google Drive REST Api: List Files by File/MIME Type

April 13, 2019
List all Google Sheets

Setup Setup Android Google Drive REST API.

List all google drive files which is Google Sheets.

var pageToken: String? = null
do {
    val result = driveService.files().list().apply {
        q = "mimeType='application/vnd.google-apps.spreadsheet'"
        spaces = "drive"
        fields = "nextPageToken, files(id, name)"
        this.pageToken = pageToken
    }.execute()
    for (file in result.files) {
        Timber.d("name=${file.name}, id=${file.id}")
    }

} while (pageToken != null)

NOTE: List of Google Drive MIME Types. Mime query could be "mimeType='image/jpeg' or mimeType contains 'image/' as well.

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.