I've implemented backup/restore of SharedPreferences using BackupManager as per the Android docs, but I'm having trouble restoring preferences to a second device. I believe the implementation is fine, since I can restore settings to a single device, i.e. if I run the app, make changes, uninstall and reinstall I get the modified preferences that I expect. However, if I subsequently install the app on a second device, I don't see the changes, even if I use the bmgr tool to force a backup on the first device and force a restore on the second device. Both devices have the same Google accounts, and both devices successfully restore their own backed up preferences on reinstall. I just can't get them to restore changes made from a different device.
If I install the app on a new device, I would expect it to restore the latest preferences, never mind from which device the backup was made. I've also set the android:restoreAnyVersion="true" flag, but that made no difference. What am I missing? If the devices use different transport services, could that cause the problem I'm seeing?
Related
In my app user can choose custom files to be used instead of some default settings. File's info is stored by its URI and I have hard time handling case of Backup Service restoring whole app, when all the restored URIs will be invalid.
App will turn to using default settings whenever it detects invalid URIs (not pointing to custom files), however I would want to inform the user about this fact after restore is performed, so he knows why app is using default settings.
Is there any way to detect when app was restored using BackupAgent?
So far I didn't find any proper tool for detecting when app was restored with use of a Backup Service, however I found a workaround:
context.packageManager.getPackageInfo(myPackageName, 0).firstInstallTime always returns time of install of the current instance of the app, so it is possible to store this time using backed-up SharedPreferences and then comparing it with the time received from packageManager - if it is "newer" than the one stored in SharedPreferences, then it means the app has been restored by a Backup Service.
I am making an android app. In this app I am trying to save my app from destroying on reboot or factory reset. can anyone help me out?
Apps won't get deleted if you reboot the device. About the second part(factory reset), the whole point of a factory reset is that everything on the phone will be deleted and restored to factory settings. If you want to keep your app even after that you'd have to install your own OS with the app installed as a part of it.
Also, if a reboot is somehow "destroying the app", something is very wrong with the app and you need to find out what it is.
Assuming you mean by "Save my app" that the app .apk should be still present and installed, thats impossible for a factory reset, like the name suggest its a reset.
If you want to save the settings of the app prior to rebooting, you can do that with a background service, which can be also called when the phone finishes the reboot.
I'm working on an Anti-Theft app. Supposing that my phone is stolen, the first thing a thief will do is factory reset it, what means all apps and data will be lost.
I can convert my app to a System App and it will probably "survive" a hard reset but its data will be lost. Is there a way to keep the app and its data after a reset?
If it's not possible to keep its data, I thought I could store its settings in a file, but it would be erased too. Is there also a way to keep a file after a reset?
Edit: I don't want its data. I want its data not be erased after a factory reset cause erasing its data means erasing all user settings. Since I'm developing an anti-theft app, if a thief resets it, the app should keep its data (user data like a email and phone number) to contact the owner even after a reset made by the thief...
Why do you want a copy of the data after it's stolen (????). May be you have a use case. Anyways, if you are basing your app on API level 23 and above, you can have a look at this - https://developer.android.com/guide/topics/data/autobackup.html
This kind of automatically does what you wanted to achieve.The backed up data is on Google drive of the user account but it's of no use unless restored. Funny thing is, the autobackup feature would actually restore this data after the app is installed again (and the same user has logged in).
This will not really help if you don't have the phone (i mean if it's stolen :)). But if you want to persist app data across app uninstalls and factory reset, autobackup would do the trick for you (available only on API level 23 and above)
It is possible to recover data once a mobile is factory reset or so was uncovered by some Cambridge University researchers in the paper titled Security Analysis of Android Factory Resets published in 2015. I haven't had much time to go through it, but it looks promising.
It seems they did manage to get master tokens even after factory reset by utilizing some flaw in android system where the composition of flash drives make them dangerously hard to erase. Seems something you can experiment with depending on the usage. Do go through it once.
I have an app for Android, that saves data to sqlite database in a common way. As the user works with the application, the data is changed etc. So far no problem...
But when the user use some back-up software (like Titanium Backup or others), make a backup of the application, he can restore the data to old state. I need the way to protect application from this or to detect the restoration and handle it.
The simple workflow:
Install APP
Work with APP
Reach the STATE1 of APP's database
Back-up the APP (with any backup/restore application, the device can be rooted)
Work with APP
Reach the STATE2 of APP's database
Restores the APP (or just data) to STATE1 - this is the point I need to deny or detect on the next execution of the APP.
So far I played with the Access-time detection and comparsion, but it seems to be really un-reliable through different devices and ROMs.
Thank you.
To do this you need to save some state off the device, or at least outside of the data directory. The easiest way is probably to save the fingerprint of the DB file in some 'hidden' directory on external storage (SD card). Or if your app has Web login, etc. store the fingerprint for each user.
In any case, the user has full control over the device so you can't prevent this 100%. Your app needs to gracefully handle any changes in the DB or simply fail if it detects a fatal inconsistency.
I have an Android application using the Data Backup service. After installing it using Eclipse on a device I can save some data and they become backed up well so far. I can also wipe the data and have them restored. This works as well. If I now take another device and install this application (again with Eclipse) like I'm going to switch the device, the restore process gets executed but don't deliver any data. (like there aren't any)
I'm asking me why. The package is the same, the google account too. Have I missed something in how data are mapped to apps?