Completely uninstall and reinstall Android app on update? - android

I want to publish a new version of my app. But I want it to reinstall again.
Like first uninstall and then install(like first time installation). Is there anyway that I can do it? Or force users to first uninstall the app?

If you sign the new apk with a different key, users will hit an error when they try to upgrade an existing installation. That’s probably the easiest way to do it without changing the package name.

As Jens said you can't do this really unless you reinstall with a different package name (not a good idea either.) You have to detect your version and manually reset your preferences etc. if you need to. This is a pretty annoying feature of android. I've been developing a mapping application that has the exact same problem with storing some of the background data.
You can usually check where your preferences get created for the first time. A lot of people do a if(preference !=null) to set them up, since in a pre-installed app you already have that preference in the bundle it will not update or generate a new one.
Try setting the preference checker to be if(preference != newValueOfPreference)
If that's not how your bundle data is generated on install you'll have to find out how it is generated and get at that hook.

Related

how to save my app preference and retrieve them after re-install or change of device

I'm new to app dev...
I read somewhere in the doc: "...In most cases you want to use SharedPreferences as it is automatically backed up and migrated to new devices..."
On first install my app saves a few settings with SharedPreferences. It works great but if I uninstall the app or install it on another device the preference settings are lost.
How can I have these settings saved online within google somehow to be able to retrieve them if the user changes his phone or similar...
Could someone point me in the right direction ?
I read somewhere in the doc: "...In most cases you want to use SharedPreferences as it is automatically backed up and migrated to new devices..."
Your words "backed up and migrated to new devices" is nowhere written nor its true.
We use SharedPreferences in order to minimise the database operations, its like keeping variables handy.
On first install my app saves a few settings with SharedPreferences. It works great but if I uninstall the app or install it on another device the preference settings are lost.
If you wants to store or remember the device dependent settings, use device id / imei_id and store it on your web server mysql database
Even if user uninstalls app from the device and installs again anytime in future, make a call with async task to server by sending deviceid / imei_id and fetch its settings from mysql database and show it.
How can I have these settings saved online within google somehow to be
able to retrieve them if the user changes his phone or similar...
If user changes device, you can do nothing.
One way is, keep public device_id levels keys on server.
If user changes device and uses that key, then show him a response, this key is assigned to another device, but if you are the same, wait for our support
Call him, confirm he is the same old user with new device and delete his old entry from mysql and assign old key to the new device entry
Or use OTP SMS system to identify already existing customers with unique phone numbers
If OTP authentication code is correct then fetch settings for that user from the server, delete old mysql entry, modify new entry with old key and mobile number
This should be the your direction
Edit : 2 ##
I was hoping an easier solution exist but....
There is no short cuts for developers till the date, and it will be never.
Why, no short cuts / easy ways ?
Any device ( mobile, desktop / laptop / any AI device ) which is operated by a system software, is able to perform the tasks as per it is structured.
Ex : android is java based, obviously you can Make javascript based apps, but it is the extensions to the existing system, Android still has the base of Java virtual machine. ( Dalvic / Malvic like )
So, it is always better to use native java
Yes, Kotlin is best option now a days and better than hybrid approach
Every way has its own advantages, disadvantages
If you are developer, should go with native approach
Now your java code never knows, which version it is running on, so you have to, check android versions programming wise, and decide the flow for above Marshmallow & below marshmallow too, and it is explicitly done by developer by coding.
Ex, once user registers, he never shown please register again screen, it is not the magic, nor google, nor, java, nor android does anything, developer has decided, planned, architectured, designed, coded, tested that.
Even developers needs to take care of exceptions, you need to handle it in order to save your app from crashing.
In short developer is god, who creates his own universe, and everything is pre-planned and verified thats it.
You should use allowBackup = "true" in your manifest file. More details can be found here: AutoBackup

Android-How prevent manual installation of android application

I have an application A that launches an intent to install application B(which is present in app A's data folder).
Once application B is installed, file managers like ASTRO can backup Application B's apk file.
So I want to prevent the user from manually installing it(say if he clicks on the backup apk file of Application B it should not install).
Is there a way to disable manual installation...?
But there are two ways to monitor the app.one is, you can use File Observer to
monitor the apps. whenever the apps been taken as back up do stuffs to prevent it. Another way is
For eg: if it's storing in sdcard\am\ use like this.
File f=new File("\mnt\sdcard\am\abc.apk");// file location of your app
{
if(f.exists)
{
f.delete();
}
}
For File Observer,have a glance of this.It might help you.
http://developer.android.com/reference/android/os/FileObserver.html
Can you find the location where the backup is taken and delete the apk.
If APk is available to the file manager then it can open it and install it, I am not aware of any way to stop it as its out of your application scope.
This isn't possible on AOSP Android.
The Install from unknown sources option is a setting in Settings.Global (previously in Settings.Secure) and cannot be controlled by third party applications.
However, it is possible do achieve this if you're willing to modify and compile Android itself for each and every device you want to use this on, as is done by AT&T on some of their devices.
The best you can do is try to find the backup file and delete it if you have access to that part of the storage.
Not sure if it's feasible, but I would solve this by having application A spit out a code that has to be manually entered (like a two step verification) on application B is installed, and then verify it server side. So that way the rogue install like you mentioned would be rendered useless. Maybe you could pop up an error to the user informing them of this.

Add Custom Confirmation before uninstall my Application in Android

I am new in Android. I want to add one custom Confirmation before uninstall my Application in Android.
How I can achieve this?
Thanks in advance.
This is handled by Android and thus you have no control over what happens (or when) your app is uninstalled. In case you're worried about clean up, the data stored to the SD card and any phone setting modifications will remain after the app is uninstalled - everything else (application data/cache/shared prefs) will be deleted.
what do you mean by reuse it? if your existing data structure and logic and flow doesnt change in the application it will automatically reuse it..but if any of the steps used for saving and using it is changed then its the responsibility with the developer if it wants to reuse the data pre-existing on the device or not.
hope it helps.

Are shared preferences in Android apps deleted when a user updates the app?

If I store some user settings and information in shared preferences in my android apps, and then I update the app in the Market, will those settings be erased when the app updates?
No, the Shared Preferences will remain.
To make the answer simple: NO in normal circumstances.
The update process only replaces the apk file(and so what is in it for
example drawables,...) and does not alter databases,sharedpreferences
and any other files that generated in run time(probably in this
case,new App is installed with the UID that is equal to UID of
previous App).
But following this thread it seems that there are cases when data could be lost. Like changing Copy PROTECTION FROM ON to OFF OR OFF to ON.
Quoting the answer:
It turns out when we posted the update copy protection was turned off,
but for our initial release it was turned on. Which caused all our
shared preferences to get lost, we could no longer create private data
files, and the game started randomly crashing.

Android Marketplace: Changing application's package

Any android developers had any success changing the package name of your application (in the manifest) of an application already being distributed in the Market?
During my upgrade progress, I decided to change the package name slightly, which means that android identifies it as a new application. So, I suppose saved preferences will be lost, but I'm really hoping there are no other "surprises" for upgrading users.
Cheers!
It's not that the saved preferences will be lost, it's just that Android will set it as a completely new and seperate program which cannot access the old application's preferences.
However, if you sign your applications with the same signature and and give them the same userId then they can share information and you could migrate the original application's information to the new one.

Categories

Resources