Is there anyway to know that application launches firsttime? - android

Is there anyway to know that when an application is launched for the firsttime? I dont want to use sharedpref because when the user cleardata manually it clears all the data.

That is the point of clearing data, the user may want to tell your app to consider itself freshly installed without having to necessarily uninstall the app. You should not be trying to break that expectation. That said.....
You could create a file on the SD card and check for the existence of that file to determine if your app is being run for the first time.
Do not use the normal openFileOutput() calls in android as that will be cleared when the user clears data as well.
Unless the user wipes all files on the SD card, the file should remain in existence. Also, you can do both, a shared preference and the file and then check for one or the other, just in case.

Use your own server. Just store the unique android id on your server in the first time user launches your application. But you need internet for this.

Related

How to detect when app was restored using Backup Service?

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.

Android: How to keep an app AND ITS DATA (or a file with its settings) after a factory reset?

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.

Is it possible to write a file or set a setting that can not be deleted by a user in Android?

I want to, in my Android app, allow the user to set a countersign - a password of sorts, but one that is not used to log on to the app but possibly at some other point remotely. A Broadcast Receiver would watch/listen for it, and if it appeared, respond appropriately.
This would (potentially) be used by the owner of the device remotely (from another device).
However, if the person who currently had the device knew about this feature, he may be able to delete the file on which the password is stored or delete the setting that holds the value (or change it).
Is there a way to programmatically write a file or set a setting that can neither be changed or deleted, at least not without knowing the value (which will be encrypted)?
For ordinary users, put the file on internal storage (e.g., getFilesDir()). They have no access to those files.
For users of rooted devices, there is no way to prevent them from deleting a file.

Perform action after Clear Data of my application

I want to be notified when the user or any other application Clear the data of my application (e.g. User click on Clear data button from app info). Is there is any way to know that this action was taken.
I expect to find Broadcast intent that I can receive to handle my action! is it possible? IF not are there any other way to know or not?
I expect to find Broadcast intent that I can receive to handle my action!
There is one, but your app cannot receive it. Presumably, this is to prevent malware from trying to interfere with this process somehow. If the user wants your data to be cleared, please allow it.
IF not are there any other way to know or not?
IMHO, an app should be idempotent with respect to application data. In other words, the app should treat a fresh installation identically as it would treat starting up for the first time after its application data has been cleared, which would also be identical to the app having been uninstalled and later reinstalled. Any other behavior either has privacy ramifications (e.g., trying to use some device-specific identifier and record whether the app had been installed here before) or clutter ramifications (e.g., storing some file on common external storage and checking for its existence when your app realizes that it has no application data on internal or its portion of external storage).

How to protect/detect database restore on Android device?

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.

Categories

Resources