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

时光总嘲笑我的痴心妄想 提交于 2019-11-29 11:41:56
y2ducky

It looks like Google Play services has a problem. (https://stackoverflow.com/a/26541831/2228408) For testing, you can do it by clearing Google Play services data (Settings > Apps > Google Play services > Manage Space > Clear all data).

Or, at this time, you need to implement it by using Drive SDK v2.

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<Status> syncCallback = new ResultCallback<Status>() {
    @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<DriveApi.MetadataBufferResult> metadataCallback =
        new ResultCallback<DriveApi.MetadataBufferResult>() {
    @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!

I think you are correct that it is by design.

By inspection I have concluded that until an app places data in the AppFolder folder, Drive does not sync down to the device however much to try and hassle it. Therefore it is impossible to check for the existence of AppFolder placed by another device, or a prior implementation. I'd assume that this was to try and create a consistent clean install.

I can see that there are a couple of strategies to work around this:

1) Place dummy data on AppFolder and then sync and recheck.

2) Accept that in the first instance there is the possibility of duplicates, as you cannot access the existing file by definition you will create a new copy, and use custom metadata to come up with a scheme to differentiate like-named files and choose which one you want to keep (essentially implement your conflict merge strategy across the two different files).

I've done the second, I have an update number to compare data from different devices and decide which version I want so decide whether to upload, download or leave alone. As my data is an SQLite DB I also have some code to only sync once updates have settled down and I deliberately consider people updating two devices at once foolish and the results are consistent but undefined as to which will win.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!