Save data between different package/apps - java

I have both a free and a paid app. If the user first tries free version and acquire for example 10 gold and then upgrade to paid version I want him to keep those 10 gold and not do a fresh start.
So is there way to share and access data between apps? And I don't want to save it to root of SD card because user can easily modify it that way.

I think some developers circumvent this by using their paid app just to check the payment (if it's installed, you've paid for it) and keep everything (code wise) in the free version. You could as well just encrypt/decrypt the data written to the SD card. This would as well make it easier for the user to backup/restore those saves (and nothing would be lost in case the app is reinstalled or something like that).

You can create a file in application data folder. And save it there.
/data/data/your_complete_package/your_data_filename
And of course you need to encrypt it with something unique to this phone.
So they wont be able to move this file to another phone to use.
Note that file under app data folder will uninstall together with your App.

I think Android Content providers may solve this problem:
http://developer.android.com/guide/topics/providers/content-providers.html
Content providers manage access to a structured set of data. They encapsulate the data, >and provide mechanisms for defining data security. Content providers are the standard >interface that connects data in one process with code running in another process.
Your app can implement ContentProvider and export data uri you need to share, than your free & paid version can share data through ContentProvider , just like how you access Google Contracts.
BTW,ContentProvider support SQLite & XML , which means you can store it in memory or sd card as you want.

My solution for this would be to maintain some kind of a remote server that holds all the data for users. Users login when entering the app, authenticate themselves with the server, and have all their data available.
Any local solution isn't persistent. What if a user gets his/hers app deleted? if the phone is damaged and the app is unrecoverable?
As a paying user of any app i would like to have my paid data portable through different devices.
Just my 2 cents on the matter...

Related

How to setup Firebase Storage storage subscription??? So users use my app but they have to pay for extra storage

I'm creating a lecture recording app that makes it easier for students to share and learn together from a recorded lecture. This app stores mp3 and png files on Firebase storge. Each user will have 100MB of storage for free (this is around 4-8 lecture that they can record). The problem is that users may need more memory and I cant afford it pay all from ads, therefore I want to add a monthly charge for those users who need more memory.
Now I'm not sure or have any experience in any money transaction by code. Can anyone give me an idea or what I can do to solve this problem?
P.S. I was also thinking of using Google Drive API to allow the user to save their recorded lecture on their own cloud, but I'm not sure if that will give me as much functionality as firebase storage.
If I understood the requirement correctly, this is what you'll need to implement.
In-app subscriptions: docs
Server-side verification of those subscriptions — in your case a Firebase Function, which you'll call from your app when the user subscribes, and which will verify the legitimacy of the purchase and grant the user profile a custom claim (i.e. a flag on their profile) saying they have access to more storage. My question/answer may help you out. More on custom claims here.
Logic that verifies that whenever a user uploads a file, their total folder size doesn't exceed the limit (100 MB or more, depending on whether that custom claim is set). Unfortunately there's no way to check total folder size directly in Storage Rules, so you'll have to write another Firebase Function, which will be triggered whenever a user uploads a file — docs.
Now, I'm not so sure whether it's possible to get total folder size from Functions as well, therefore you may also need to write your own logic that would keep track of how much storage space a user had already used (e.g. keep a database record) and use that to verify whether the newly uploaded file should be kept or discarded.

How to save application data for use across users in OS X

I have a Mac Java application that needs to persist data across reboots. The data needs to be saved so that any user has access to it. E.g. an SQLite database file that can be used for all users.
It looks like the /Library/Application Support/ folder is supposed to be used for this, but I'm not able to write to it without making my app run as root or changing the permissions of the file to rwxrwxrwx.
What is the proper way to save application-level data on Mac?
The developer documentation covering this is a bit of a large topic:
https://developer.apple.com/library/Mac/referencelibrary/GettingStarted/GS_DataManagement_MacOSX/_index.html#//apple_ref/doc/uid/TP40009046
https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010672
According to the File System Programming guide you should make a specific subdirectory inside /Library/Application\ Support for your app to store app data common to all users on the system. I'd use reverse domain name notation such as com.yourcompany.yourapp or something else unlikely to collide with another app's use of the common directory for this.
You might also look into using an existing app bundler for OS X such as https://bitbucket.org/infinitekind/appbundler rather than hard code paths to file locations.

Android, Not sure if I should store to the internal storage or external storage

I have an app out there on the market already The app is not a game just an informative app with lots of pictures and stats and I received a comment from someone stating that the size of the app being 20Mb is being stored on the "internal storage which isn't fair and that some of it should be stored on the SD card."
Now I am still trying to learn everything about android coding but is this a big deal so that I should move all those images to the external storage like the SD card? Is 20Mb to the internal storage too much or what number in Mb should I look out for to know when to store to an external? I looked at the storage documentation here and it states that the user can modify when they enable USB mass storage to transfer files on a computer, so does this pose a risk to my app breaking if the user modifies/removes/changes anything?
You are looking for installLocation. Just change one thing in the manifest and let users choose where the APK is installed.
Note: By default, your application will be installed on the internal storage and cannot be installed on the external storage unless you define this attribute to be either "auto" or "preferExternal".
This is no different to a computer having two hard drives, a boot disk and a second disk.
Obvious if you can store using the second disk/external storage, you are generally better off as the internal storage has many uses and usually fills up first.
Generally speaking it is best to leave it to the user to decide but I would store on the external storage by default.
For an older phones it is a big deal, believe me. The best option would be to let user choose, which storage he wants to use, in some sort of configuration dialog.
If the app requires those files then do not put them in external storage as that will allow the user to remove them.
If they can be removed/altered then you should put them in external storage.
You could also do a mix of the two so that the size could be reduced without sacrificing the necessary components.

When caching images and data should you use Internal or External Storage?

I've read this Android save app settings/data in Internal/External Storage but I don't think i've really got an answer.
I'm developing an app where I should store some "cache" data, like a dozen of images and some strings (json).
Initially I was storing all that on the sdcard, (external storage) but later i thought that this could be deprecated by the SDCard deprecation in most recent devices.
After reading a bit, I understood that external storage is not only sdcard, but "a removable storage media (such as an SD card) or an internal (non-removable) storage" so it should not be deprecated but...it's shared space, and there is not ownership over the files stored there, so the first problem was that I was unable to delete them when the app was deleted.
So I changed to the Internal Storage, to avoid having the files/images "public" and also having them removed after app deletion.
Is this the recommended approach?
On devices older with low internal storage but with a lot of space in the SDcard is this a good approach?
My application supports from 1.6 to 4.0 (so far) so I have a lot of legacy devices... and I must have the app working (well) on all.
Looking forward for some interesting answers!
It depends on the type of data you are wanting to store.
You mention it's cached data so myassumption is that it should not matter if for some reason it all disappears. This leads me to believe that you should be using the getCacheDir(). In this case the system will remove files if the cache becomes too big so devices with low internal storage shouldn't present a problem (although it is recommended to manage this your self anyway), it's relatively secure and it will be managed by the app so if there is an uninstall it will be removed.
getExternalCacheDir() was introduced in 2.2 so isn't any use to you unless you would like to detect the version and switch between the 2 caching directories getExternalCacheDir() doesn't provide security so data could be accessed by anyway with access to the SD card. The only reason I could think you might want to do this is because of size of cache you desire but from your description the data doesn't seem excessive.
UPDATED from comment:
although this is a specific case where it's cache...but I don't want
it to be deleted whenever the system wants. It's the kind of cache
that I need the to app decide when to purge. What is the main concern
of storing in on "normal" internal storage without being on the cache
dir?
If you get to the stage where the system is cleaning up internal cached data because storage is so low then you should probably leave it to clean up this sort of app data. By using standard internal data storage you are bypassing this safe guard which would probably create more unpleasant problems than having app data deleted.
If your data is of high importance then I would suggest trying to identify specific data that is more important and managing that separately. If this data you identify needs to be secure then internal storage using files or a db (depending on the data type) seems like your only real option but you would have to be wary of this data building up.
UPDATED from comment
What do you think about using SharedPreferences to save string data?
Is there a limit on SharedPreference string saved size? Is it a (good)
possibility?
I have used shared preferences to store relatively big json strings in the past with no problem, I find it's simpler than using the databases for primitive data types (and strings) where there are limited values to save. However when you have images or lot's of values, management becomes more complex. Also you will have the same problem as you would with standard internal storage in terms of storage space.
I would keep images on the external storage, probably in a "hidden" folder (adding a dot at the beggining of the folder's name: .folder) and also a the Media Scanner "avoider" (.nomedia), because, as you pointed, you want the application to work in old devices, and precisely those devices don't have to much internal memory.
You can also add an option in your application to remove that folder, so in case the user wants to uninstall, he can do that before.
I would use internal storage for cache. This will take away the chance of a user being able to access the files used in your app. I would go for internal

Android application backup and restore?

For the application I'm creating, I'd like users to be able to backup their application data (to an SD card for instance). What I mean by application data is the preferences and SQLite database. I'd also like to make it possible to restore the data.
Is it possible to do this with BackupManager? If yes, can someone give me a simple example.
BackupManager is for saving your data to the cloud. To have something backed up to the SDcard, you could write some kind of a service for your application which does this. All the files/dbs/preferences can be written to a folder.
But, this approach also has a risk if the user formats his SD card or deliberately deletes the folder. You can have no control over that.

Categories