Android Drive API查询

时间:2018-02-11 21:57:19

标签: java google-drive-api

我正在尝试在我的应用中实现查询过程,但应用程序始终会找到结果。这是我如何设置查询:

Query query = new Query.Builder()
                    .addFilter(Filters.eq(SearchableField.TITLE, "Foo.txt"))
                    .build();

Task<MetadataBuffer> queryTask =
                    mDriveResourceClient
                            .query(query)
                            .addOnSuccessListener(this,
                                    new OnSuccessListener<MetadataBuffer>() {
                                        @Override
                                        public void onSuccess(MetadataBuffer metadataBuffer) {
                                            Log.i("ARRIVE", "File Found");
                                        }
                                    })
                            .addOnFailureListener(this, new OnFailureListener() {
                                @Override
                                public void onFailure(@NonNull Exception e) {
                                    Log.i("ARRIVE", "File Not Found");
                                    finish();
                                }
                            });

无论我放置什么标题过滤器,它总能找到一些东西。我得到&#34; File Found&#34;每次。如果我尝试访问结果应用程序崩溃,我猜是因为没有什么可以访问。有没有人对我应该做些什么做出任何建议? 非常感谢你。

1 个答案:

答案 0 :(得分:0)

尝试添加OnCompleteListener以检查任务是否成功,如下所示:

Query query = new Query.Builder()
                    .addFilter(Filters.eq(SearchableField.TITLE, "Foo.txt"))
                    .build();

Task<MetadataBuffer> queryTask =
                    mDriveResourceClient
                            .query(query)
                            .addOnCompleteListener(MainSettingsBackup.this, new OnCompleteListener<MetadataBuffer>() {
                                @Override
                                public void onComplete(@NonNull Task<MetadataBuffer> task) {
                                        if (task.isSuccessful()) {
                                          Log.i("ARRIVE", "File Found");
                                        } else {
                                          Log.i("ARRIVE", "File not Found");
                                        }
                                    }
                                });