Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh the content when accessing Google drive with SAF

I'm trying to access PDF files from Google drive within my app with the following code:

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("application/pdf");
startActivityForResult(intent, MY_ACTION_OPEN_DOCUMENT);

which was taken from Google's documentation directly. I'm able to get the file picker to appear. However there are 2 problems:

  1. There is no way to refresh the content of the file picker.
  2. Files newly added to the Google drive account will not appear until I go to the actual Google drive app and perform a refresh there.

I'm wondering if there is something missing in my implementation. I tried to search the web and surprisingly found nothing relevant. More surprisingly I got the same problem with the gmail app.

Thanks in advance.

like image 394
Paul L Avatar asked Nov 08 '22 14:11

Paul L


1 Answers

Storage access framework does invoke callbacks on active/selected provider (queryDocument and queryChildDocuments). It is up to the Google drive document provider to sync and notify SAF. SAF even supports streaming files of a large size. The sync logic itself is implementation logic dependent on doze mode etc.

In worst case, users can always pull down to refresh on the documents viewer to trigger the same callbacks.

https://medium.com/androiddevelopers/building-a-documentsprovider-f7f2fb38e86a.

like image 61
Vairavan Avatar answered Nov 14 '22 22:11

Vairavan