0

I am wondering if Shared Preference is a clean way to do what I am trying to accomplish. I am building an application where I need to have the ability to allow a 3rd party to pre-setup the application on the phone prior a user using it. I figured one way of doing this would be for the 3rd party to supply a Shared Preference XML file and for the application to attempt to read it at start up. If there is no custom file provided the application will start in default conditions.

I understand that this can be done using a regular file as well and I could just read and parse through a file, I am just wondering if Shared Preference is the clean way of doing this.

I am still somewhat new to Android Development so I also welcome better ideas of accomplishing this.

Thank you

Andrei
  • 33
  • 1
  • 9
  • It depends on how you plan for the property file to be "put" int the application's folder "before" the app is used by the end users. How are planning to do that? – Juan Feb 23 '18 at 14:18
  • Well the 3rd party has virtual access to my device. So they will be able to supply a file into a directory I specify for them. – Andrei Feb 23 '18 at 14:55
  • I am not sure what "virtual access" means. I assume ithis is intended for an app on limited number of installations done manually (not through google play). See if this helps you with the file location: https://stackoverflow.com/questions/6146106/where-are-shared-preferences-stored – Juan Feb 23 '18 at 15:02
  • Virtual access is essentially what remote desktop is for windows. And I have seen that article. As I am somewhat new to Android I wasn't sure if that was a permissions blocked directory or I am able to browse to it once the application is installed. I also posted this for a possible better way of accomplishing this, I am not married to the shared preference idea. – Andrei Feb 23 '18 at 15:29

1 Answers1

0

Once the the app is installed on a device you will not have permissions to write to any of the app's folder. You will need the app itself to install the configuration file when it is started up.

This would be to read the configuration file, which can be a properties file, and have the app write or copy the values to the sharedpreferences.

To have the app get the properties file, it could be done by downloading the file from a server or even reading it from the ExternalFiles folder of the device (For the second alternative you will need to set the corresponding permissions in the manifest, and also request permissions at runtime for local storage).

The app, upon startup, will have to check if it has been initialized with the properties file (which can be be a flag in sharedpreferences) and if not try to get hold of the properties file to do the setup).

Juan
  • 5,525
  • 2
  • 15
  • 26
  • Thank you, I had considered this approach but hoped maybe Android contained a predefined way to do preset up. I like this though and will most likely go with this. – Andrei Feb 23 '18 at 16:46