Search code examples
androidjsonkotlinconfig

Android: where to store json file to be accessible to both app and user?


I'd like to use a small local JSON config file with a few fields, so my app can read it and know what to do. This file will not be shipped as part of my app. The idea is that the user creates the file with the desired parameters, and transfer that file to a specific location on the device for my app to fetch it on startup. What would be the best/proper way to store the file so it is accessible for both the app and the final user? There is any path that is usually used for this?

I have worked before with json through http and with local jsons in the app assets folder, but I've never had the necessity of give the user access to create/modify the file.


Solution

  • The user can put the file anywhere they want on the external storage. The issue comes with dealing with it in your app.

    You can no longer request the READ_EXTERNAL_STORAGE permission and be able to get it on Android 13+ so your best bet for this case is to have your app launch the ACTION_OPEN_DOCUMENT intent where the user picks where the file is and you handle the returned uri of the file after it is selected