javaandroidgoogle-drive-apigoogle-drive-shared-drive

How to save and load user prefs (1 txt file) to user's google drive (same as Whatsapp, Viber and other apps) [Android Studio]


based on recent google changes to drive (drive api got fully deprecated on feb 2023) and most of answers and git examples are focused around that i would want any opinions or suggestions on how to save and load user prefs (1 txt file) to user's google drive (same as Whatsapp, Viber and other apps) in a android app. Being prompted to log or select a gmail account then click and you're done. In other words just a simple string to be written to the user's cloud drive, so that it can be easily accesed from other devices if logged in the same app with the same account.

It is highly appreciated if you could provide an example/sample/link, since i have tried Google's guide which only hot me more mixed up.

I have searched GIT repos for such, yet all i got are old drive based solution (which got fully deprecated as of Feb 2023) or Drive Rest which requires developer console extra setup.

To be clear, this save-load is for users on their personal accounts, so telling them to go to developer console won't do.

Thank you in advance


Solution

  • Based on your use case I think you could try using the Application Data folder from Google Drive. According to the documentation:

    The application data folder is a special hidden folder that your app can use to store application-specific data, such as configuration files.

    You can create files within that folder only for your application, and as the folder is totally hidden for the user they will not be able to interact with it easily.

    This folder is only accessible by your application and its contents are hidden from the user and from other Drive apps.

    When using the files.create method to create a file within the folder you need to make sure of adding appDataFolder as parent, or when retrieving the file for example you need to add appDataFolder in the spaces parameter to reference that specific folder instead of the regular My drive section that the user is able to see and manage.

    In the official documentation below you can find code samples on how to use it if you need as well.

    References: