App Folder files not visible after un-install / re-install

后端 未结 3 431
面向向阳花
面向向阳花 2021-01-14 05:57

I noticed this in the debug environment where I have to do many re-installs in order to test persistent data storage, initial settings, etc... It may not be relevant in prod

3条回答
  •  清酒与你
    2021-01-14 06:12

    Try this approach:

    Use requestSync() in onConnected() as:

    @Override
    public void onConnected(Bundle connectionHint) {
        super.onConnected(connectionHint);
        Drive.DriveApi.requestSync(getGoogleApiClient()).setResultCallback(syncCallback);
    }
    

    Then, in its callback, query the contents of the drive using:

    final private ResultCallback syncCallback = new ResultCallback() {
        @Override
        public void onResult(@NonNull Status status) {
            if (!status.isSuccess()) {
                showMessage("Problem while retrieving results");
                return;
            }
            query = new Query.Builder()
                    .addFilter(Filters.and(Filters.eq(SearchableField.TITLE, "title"),
                            Filters.eq(SearchableField.TRASHED, false)))
                    .build();
            Drive.DriveApi.query(getGoogleApiClient(), query)
                    .setResultCallback(metadataCallback);
        }
    };
    

    Then, in its callback, if found, retrieve the file using:

    final private ResultCallback metadataCallback =
            new ResultCallback() {
        @SuppressLint("SetTextI18n")
        @Override
        public void onResult(@NonNull DriveApi.MetadataBufferResult result) {
            if (!result.getStatus().isSuccess()) {
                showMessage("Problem while retrieving results");
                return;
            }
    
            MetadataBuffer mdb = result.getMetadataBuffer();
            for (Metadata md : mdb) {
                Date createdDate = md.getCreatedDate();
                DriveId driveId = md.getDriveId();
            }
    
            readFromDrive(driveId);
        }
    };
    

    Job done!

    Hope that helps!

提交回复
热议问题