Backup SharedPreferences in Android to local Server or Device - android

I am developing an App for a lot of Devices, so that they aren't registered to a Google Account.
But I want to backup my SharedPreferences somewhere. In best case in a folder on the device.
So I tried to use the BackupAgentHelper, but this backups only to Google or can it backup somewhere else ?
Alternatively is there a way to copy the SharedPreferences to a place on the sdcard?
The problem is when I doing a update to my app (not trough the market) I lose all my data.
PS: Sorry for my bad englisch

Using BackupAgentHelper only uses the in-built Google backup system, and won't do anything useful for you if you don't have a Google Account on the device.
SharedPreferences files are just regular files in your app's data directory. If you want to copy them to the SD card, or your own server, on command, you can do that using the normal File API. It sounds like for what you're trying to achieve, it might be easiest to just call Context.fileList() to get an array of files in your apps' internal storage, and then iterate over that array, copying each file to a folder on the SD card.

Related

I want to password protect my local phone directory folder in android

I want to password protect my local phone directory folder
This folder (directory) has been created by my application at run time with password protection.
My application can open this folder and used for self.
Any one can't open this folder manually. It is possible in android.
Thanks in advance.
This is not possible on Android.
You could create your folder on the internal memory, so that only your app can access it on normal devices. However, anyone with a rooted device will be able to browse your folder using a file manager, and other apps will also be able to read its contents if given root access.
A folder on the external storage is accessible to all apps with the READ_EXTERNAL_STORAGE permission, so you'll want to avoid using that.
At any rate, there is no 100% effective way to secure your folder such that only your app can access it.
However, you could try encrypting your data. This is what many apps like whatsapp do. Even when Whatsapp backs up the chats to the external storage, it is AES encrypted so that while others can access the data, they can't read it without decrypting it first. I would recommend that your try encryption

Private sd storage

I have an app which takes pictures and saves them to sd, problem is that picture modification (delete,rename,ecc.) should be done just throught the app so I need a way to make the pictures folder not accessible to user...is it possible?
The only way is to encrypt the files that you store. There is no way to prevent users mount the sdcard to access every file stored in it.
In the common Android architecture the SD-Card is formatted using FAT32 filesystem. As FAT32 does not support any access control mechanisms you can not rely on that.
Therefore the only possibility is encryption. Create an encryption key and store in the private app data folder. Then use it for encrypting the privacy sensitive files you want to store on the SD-card.

The best place to store a user-accessible configuration file

I have a project consisting of four programs for different platforms; all of them use the same XML-based settings file format. I want to be able to manually modify/overwrite it outside of the application. On Windows, Windows Mobile and Linux I'm using "user.home", but on Android that alias isn't implemented. I'm thinking about simply putting it in the Downloads directory, however, that doesn't feel right.
I can't be the only one, who needs that kind of functionality. Or this isn't Android-way? Any suggestions are appreciated.
EDIT: I'm OK with the settings file not being available all the time (i.e. SD-card removed), it's used only on the start-up of the application.
Store it in getExternalFilesDir(). This would work only if the device has an external storage. The user would be able to access it.
However, take note of the following from the docs:
External files are not always available: they will disappear if the
user mounts the external storage on a computer or removes it. See the
APIs on Environment for information in the storage state.
According to Android data storage documentation you have 5 options:
Shared Preferences. By default this will use file /data/data/your.package.name/preferences/user_preferences.xml
Internal Storage. Here you can use something like /data/data/you.package.name/user.home
External Storage. Similar to internal storage /mnt/sdcard/Android/data/your.package.name/user.home, but if user removes memory card file will be inaccessible.
SQLiteDatabase. You can store the whole user.home file in a database blob.
NetworkConnection. Store user's config in a cloud.

Is there a way to see what data stores each app in phone memory/on sd card?

I want to track everything that apps store in phone memory/on sd card, so I can delete it if the app is uninstalled. Is this possible? If not, how can I get all the files from phone memory/sd card?
there is no way to "track" what your application creates, i think..
generally, the app stores data in the Cache directory, which is :
"<storage directory>/data/<your package name>/"
on a device which supports external storage, the "storage directory" is generally "/mnt/sdcard"
you can read the documentation to learn how to use the External storage to save files you create through your application.
I'd also like to point out that there is no way for you to know when your app is being uninstalled, so you can't delete the files before uninstall manually anyway,if that's what you intend to do. The android system itself removes the files stored in your cache directory, though.

Files internal to applications

I read this sentence, form a book
"Files: Files internal to applications, which you can store on a
removable storage medium"
and I am confused, well I expect that "Files internal to applications" saved from my app that will be accessible only from my app. and that is true when you save them internally in the phone memory.
But as the sentence says , you can save files to the sdcard also. And that is great but I think that everyone with 'external storage read' privilege set in the manifest will be able to read your file, so that doesn't make it internal to the app, it makes it publicly available to everyone.
My question is:
Is there any way to store the files in the 'removable storage medium' -> sdcard and those files to stay available only to my app, others application to be prevented from reading the content ?
I know that if you put files in data/data//files these files are only available to the app with that package name
It is possible . For that you need to encrypt the data with some private key and write to SDCARD, when ever you want to process that data you have to decrypt it . So another app can't access your data without decrypt it.
Android Encryption Example.
store the files in the 'removable storage medium' -> sdcard and those files to stay available only to my app
I don't think so, For sdcard it is not possible.
The one way is store encrypted file in sdcard and key for it is you can put (keep) in your application's shared preference in private mode and decrypt the file from your application when you want to read it. But I think it some ugly way.

Categories

Resources