I want to create a preference set which the user will not easily be able to delete/clean...
the idea i got is to create the persistence files in the public folder as and hidden folder (this way the files wont be deleted on unnistall or if the user asks for clean apps data)
my questions:
1- does anyone knows a better way? is it possible to do that using the apps private folder and somehow tag the files for no deletion?
2- is possible to use native android preferences framework and specify another file to store the properties? how?
3- does anyone know a good, SMALL and simple to use API for persistent properties similar to androids default?
Related
I'm developping an app that contains some settings like server ip, sharedpreference filename and other that I would prefer save into a single file and not hard coded somewhere in the code.
So I would like to know what are the best practices nowadays concerning the deployement of these kind of settings. More, how to access it everywhere in the app ?
The android sharedpreference allows me to save it after the 1st launch but I don't know how to deploy it with the App.
regards,
A common way to deploy arbitrary data is the use of raw resources.
Create a file with your settings and save it to the raw resource folder. When your app is run for the first time, you can create your SharedPreference instance and copy the values from the raw resource to the preferences.
One option is to create a Configuration.java class and put the configuration there. You can have different build flavors for different build types (development, production etc.)
Another option would be to use the class generated by Gradle: BuildConfig.class, where you can put some configuration data from your build.gradle script.
EDIT:
Shared Preferences shouldn't be used for that if the server IP doesn't change during the lifetime of the application.
I am new to Android development using eclipse, although not new to software development in general.
For my first real project, I am trying to modify the example SoftKeyboard that is supplied with the SDK. I want to modify one of the keys to act as a function key, when followed by a single letter key it will enter a canned string - performing a macro function.
So far so good. I have the key and graphics modified, and found where to respond. I would like to put the canned strings in an editable Properties file stored where the keyboard can find them.
That is where I'm having trouble. It seems that I can't to create and save a file. I don't know if it's read/write permission problem, whether the keyboard (it runs as a service) is not allowed to create a file, or my code is just plain wrong.
Can someone help me out – point me in the right direction?
Thank you very much.
Barry.
If these are canned files that come with the APK you install to the device and only need to read (not write), you can place them in the assets folder of your project. Then use the resource manager to load them:
Resources resources = getResources();
InputStream moduleSearchTemplateIn = resources.getAssets().open("file/name/here.properties");
If you want to read/write files on the SD card, you'll need to add a permission to your manifest. Though, for this purpose, I'd probably prefer a SQLite table.
I just have some basic questions about the way shared preferences work with Android:
1) Are the preference files part of the application itself, or are they stored elsewhere on the user's phone?
2) If I have created and modified preference files in the course of testing my app, will those preferences be the default settings for users, or do the users start with a clean slate?
1) The preferences are stored on the user's phone, of course.
2) If you want defaults, you need to program them yourself, just setting the preferences in your emulator is not going to affect anybody installing your application.
I have some configuration I want to save it in my Android application and read it whenever I need , for instance, the server URL that it should try to access like that.
Is there any similar mechanism like web.config in ASP.NET available in Android?
A central configuration file that can be set up manually and then read by the application? Any help would be appreciated!
We use a .properties file in assets folder. It works out very well for us as we support multiple carriers with this, write to it (in case some values, sent from server, need to change. This is done at app start time, thus making our code configurable from server).
You can throw things like that into your strings.xml file. But, since you can't actually modify these values in real-time (since it's a distributed application rather than running on a server), throwing it into a constants class is quite acceptable.
Use Shared Preferences.
Here's a link Shared Preferences
You can use sq lite database files for it. You have a native API to read and write those and on top of that a command line tool.
If you want to create an XML file instead, then it's no different than any other xml file (unless you are thinking about the Shared Preferences, which use an xml format to save the data, but I believe it's not the best API for your application).
I was stumped on this too, but came across Managed Configurations in the Android documentation.
Managed configurations, previously known as application restrictions, allow the enterprise administrator to remotely specify settings for apps. This capability is particularly useful for enterprise-approved apps deployed to a managed profile.
It allows you to set a default value in case you rather not getting into the enterprise admistration business but leaves that option open for the future.
There is a caveat. This only works if your app is registered for EMM. Otherwise you will retrieve an empty map of restrictions.
I am wondering about new skinning mechanism for my app. However I don't want to make my application bigger.
Is it possible to create another app, which will be able add/change files of another my app in /data/data/com.myfirstapp directory ?
You could set up aContentProvider that other apps could use to transfer data to your app, which could then save it to its own data directory.
The answer is simply no, you can access other applications from your own application but you cannot edit or change them.