Reputation: 59168
My application needs a configuration file. In the order of priority:
1) User should be able to update it by connecting the phone to the pc & select mass storage mode
2) My application needs to be able to read & overwrite
3) I should be able to distribute it with my installer
How can I do this? I checked "Using the External Storage" on this this page but getExternalFilesDir(null).getAbsolutePath()
returns /mnt/sdcard/Android/data/com.MyApp/files
and I think I cannot put files in that location with installer.
Upvotes: 2
Views: 6322
Reputation: 74780
According to requirement #1 - external storage is the only place. But you're right about #3 - your installer can not write files at that location.
You can resolve this by creating custom Application
file (see Application and <application android:name="...">
). In your class that extends Application
in onCreate
method check whether configuration file exists, and if not - create default one by copying it from application resources/assets.
Upvotes: 0
Reputation: 8142
First you can't use the external storage ( sd card ) because it is mounted when connected to PC so you won't have access to it. If you want to have access to the config file while connected to pc you have to store it in PhoneStorage. Here is the documentation for the internal storage. In order to distribute your config file with the installer you can use pre-defined config file in the Assets folder and copy it in the InternalStorage at install. So these are the basic steps
If you have some issues implementing them please feel free to ask.
Upvotes: 3
Reputation: 2802
Write it to sdcard/, let your app have permissions to read/write on the sdcard. If the file is missing assume that your app is being run for the first time and write the config file to the sdcard (you could include a template as a resource in your apk)
Upvotes: 0