Android Google Drive Rest Api Search Files by File/MIME Types and Name

April 13, 2019

Setup Setup Android Google Drive REST API.

val query = ...

val safeQuery = query.replace("'", "\\'")

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

} while (pageToken != null)

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


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