kotlin - HMS Drive kit 查询和查询字符串

标签 kotlin huawei-mobile-services

我是一名刚开始使用 HMS 的初级开发人员。我正在尝试编写一个代码来查找“profile.json”文件,该文件之前已上传到云中的“DebtSorter”文件夹中。我的代码(Kotlin)目前看起来像:

 var fileList: MutableList<File?> = mutableListOf()
        thread {
            try {
                val drive = buildDrive()
                val request = drive.files().list()
                var cursor: String?
                fileList = ArrayList()
                do {
                    var result = request.setQueryParam("fileName contains 'profile'")
                        .setOrderBy("fileName")
                        .setPageSize(10)
                        .setFields("*")
                        .execute()
                    for (file in result.files) {
                        fileList.add(file)
                    }
                    cursor = result.nextCursor
                    request.cursor = cursor
                } while (!StringUtils.isNullOrEmpty(cursor))
            } catch (e: java.lang.Exception) {
                Toast.makeText(applicationContext, "executeFilesList exception: $e", Toast.LENGTH_LONG)
                    .show()
            }
        }
        return fileList
但是,返回的 fileList 始终为空,即使我将文件上传到云的根目录。我想我弄乱了查询字符串,因为我可以很好地上传文件。有人可以告诉我查询字符串中使用的语法和关键字,并可能帮助我了解代码以及如何在 HMS Drive 套件中的给定文件夹中进行搜索?

最佳答案

更新:
也可以引用演示:https://github.com/HMS-Core/hms-drive-serverdemo在demo中,线程直接执行获取文件列表的方法。

您的查询参数不正确。您无法定义查询字符串的格式。请参阅此示例查询语句。
(假设文件夹A的ID为f192358798744098816):

  • 要查询文件夹 A 中的所有文件,请运行以下语句: 'f192358798744098816' in parentFolder 和 mimeType != 'application/vnd.huawei-apps.folder'
  • 要查询回收站中的所有文件夹,请运行以下语句: mimeType='application/vnd.huawei-apps.folder' 和recycled=true

  • 查询条件父文件夹中的“fileId”回收=真不能一起使用,即用户不能查询回收站中指定父文件夹中的文件或文件夹。
    更多详情请见 official guide .

    关于kotlin - HMS Drive kit 查询和查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65096571/

    相关文章:

    android - 显示通知时华为 5.1 手机出现奇怪的允许/拒绝问题

    java - 华为设备上的文本对齐问题

    react-native - 用户尝试打开 map 工具包时它就会崩溃

    android - 无法添加名称为 'kotlin' 的扩展,因为已经有一个扩展使用该名称注册

    android - 将 Native 代码与 CameraX 集成到自定义 React Native 组件失败

    kotlin - 如何在 Kotlin 中将数据类转换为 ByteBuffer?

    junit4 - 在 Kotlin 中使用 @ClassRule

    huawei-mobile-services - Huawei Ads Kit AdListener.onloAdFailed 错误代码的描述是什么?

    java - 媒体样式 : RemoteServiceException: Bad notification posted from package

    android - 在android中启动 Activity 会打开新 Activity Kotlin的多个实例