Search code examples
c#androidxamarinmobiledocument-provider

How to force QueryRoots to fire on Xamarin app after first launch, storage provider


I am trying to implement a Xamarin storage provider as per the example here.

https://github.com/xamarin/monodroid-samples/tree/master/StorageProvider

The issue is that I want the user to log in before I render the root folders.

The method used to query the roots is the following:

public override ICursor QueryRoots(string[] projection)

This is called when the app first launches, but does not seem to be called subsequently.

If I log in (hard coded credentials) straight away, this works fine. However if I open the app so I can add some login details manually then this does not get called again and therefore does not re-render the correct roots.

Has anyone got any ideas how I force Android to re-call this method again to refresh this list?


Solution

  • You could try to call the below method to notify the system that the status of our roots has changed

     Activity.ContentResolver.NotifyChange (DocumentsContract.BuildRootsUri (AUTHORITY), null, false);
    

    you could see the explanation here https://github.com/xamarin/monodroid-samples/blob/0b301e8fd2da65ff442b5f1ed236c73ba3b963c2/StorageProvider/MyCloudFragment.cs#L66.