0
0

More than 3 years have passed since last update.

Drive KitでHUAWEI Driveでファイルとフォルダを検索する方法

Posted at

HUAWEI Driveのファイルとフォルダの検索手順

  1. HUAWEI Driveに接続する
  2. 検索クエリを作成する
  3. HUAWEI Driveに検索クエリを渡し、検索を実行する

注意点
1. 検索対象はファイルの場合、検索クエリに"mimeType != 'application/vnd.huawei-apps.folder'"を追加する
2. 検索対象はフォルダの場合、検索クエリに"mimeType = 'application/vnd.huawei-apps.folder'"を追加する
3. 検索対象はアプリケーションデータの場合、DriveRequestのcontainersに"applicationData"をセットする

サンプル

private var drive: Drive? = null

fun getFile(fileName: String, isFolder: Boolean, isApplicationData: Boolean): com.huawei.cloud.services.drive.model.File? {
    drive?.let { drive ->
        val queryFile = "fileName = '$fileName' and mimeType " + (if (isFolder) "=" else "!=") + " 'application/vnd.huawei-apps.folder'"
        val files = drive.files().list().setQueryParam(queryFile)
            .setOrderBy("fileName")
            .setFields("category,nextCursor,files/id,files/fileName,files/size").apply {
                if (isApplicationData) {
                    containers = "applicationData"
                }
            }
            .execute()

        return files.files.firstOrNull { it.fileName == fileName }
    }

    return null
}

GitHub

HMS Drive Kit Demo : https://github.com/Rei2020GitHub/MyPublicProject/tree/master/DriveKitDemo

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0