How to know if Android app is redeployed ? - android

I'm building an SDK and I have class called e.g mainClass, so in the app MainActivity I let the developers(that uses the SDK) pass data like the app key in the mainClass constructor and then they call register function that will start registration service only the first time the app was open (using preference).
The problem is when a developer changes the app key and deploys the app again (with the new app key) the preference of the app (appFirstOpen=false) stays there and registering the new app key will not go through.
I thought about checking if app key changed in the constructor but it seems like an overhead. is there away to know if the app is redployed to clear the preference or is there anyother way to get pass this issue.

To answer the question in the title, no there isn't a new deployment flag. So you will have to check other factors such as app id, in your application, or the PackageInfo or ApplicationInfo from the system. If you just wanted to wipe the data of the application you can manually clear data in Settings -> Applications, or just wipe the Preference data every time with SharedPreferences.Editor.clear().
It appears that you're having an issue when the same application run against a new app id. This would suggest to me that working with the overhead of checking the app id would be worth doing. I would suggest have one preference file per app id it will be able to handle appFirstOpen conditions.

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 First time Accept Rules to Use

I want the user to accept my application rules and terms policy to run my app.
I've thought using SharedPreferences. But what is the best way to prompt user , who has just launched my app , to accept the rules?Create a new activity which always checks in the sharedPreferences and if the variable is not set to true it will not let the app begin(It will not launch Main Activity maybe?)?Can you help me with the code?I'm not experienced with using SharedPreferences.

Creating event in calendar only once when App is installled

I am developing a Application which will create events in calendar. Events should get created only once when my application is installed and opened. I tried with using Shared preferences. But when i clear my app data, shared preferences were also getting cleared.
Please let me know how to do this.
Although Shared preferences is usually used for the use case like yours, but since you wants to be guarded against "Clear Data", You may create an empty file as an alternative.
You can check (before creating a Cal.event) if your file(whose exact name and location is only known to you) exist.
Obviously, there are many situations with this approach against which you need to protect.
1.what if user removes this file?
2.if you chose to save file on SD-card, what if sdcard is removed?
In case, if you do not want to rely on Device and data saved on device, and if your app can communicate with Server, then you can maintain this installation history information "online". Then, invoke a network call to query "installation history" info.
For this method to work, you also needs to track on which device and user, the installation was done previously.

Download content when app is updated via google play?

So this is the first time I am going to send an update for my app and I don't know about what actully happens when an app is updated via google-play,
Here are some questions those I couldn't get answer of :
What is actually updated and how this process works i.e. methods or callbacks when update is done ?
What happens to the shared-preferences file, the name values pairs change/reset ?
Let's say I want to download some file from a server , when the app is updated via google play and do some db operations with that file in the background. How can I approach this in the right way.
--Edit--
To make it more clear I want to automatically do some processing when the app is updated by user and he doesn't bother to open the app and to achieve this I am looking for a trigger that is provided by google play to my app by any intent [implicit or explicit].
You need to implement a Broadcast Receiver that gets notified when the Paackage is beeing replaced:
In your Manifest include:
<receiver android:name="my.package.MyReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<data android:scheme="package" />
</intent-filter>
</receiver>
The class MyReceiver needs to extend android.content.BroadcastReceiver
To Answer your second question: The SharedPreferences aren't affected by an update through Google Play, as aren't the files in your App's data-Folder.
One way of checking if a new version has been installed is to use shared preferences. When the app is opened, you can check if an entry for that version is present. If it's not, a new version has been installed. After your processing is done, you can save the current version number in shared preferences.
As for your second question, shared preferences are not lost or reset by the update process. They stay as they were.
You may be out of luck here as there is no clean way to do this with an already installed app. If you have in-app billing (and this is speculation) and Google's in-app billing system has a dynamic dashboard or API to register users, then, you can say setup a new unique key of some sort and track it through this in-app billing like system. This may not be possible though.
The second thing you can do is to look up users in your server database and create this file you mention for all users and hold them in server cache (for fast access). Then in your app on first launch of this new version you can quickly get this file to user. This seems to be a good safe solution.
Good Luck, this is an interesting problem and I will be looking forward to hearing how you will solve this.
Just remembered, you can also look into push notifications and pushing this data to users. But, this assumes your app has this.
#prateek User need to start the App manually from Android 3.1 to apply the Broadcast Receiver Solution. I do not think you have any option...Sorry Mate...A small advice is that, try to put a push notification handler when you really want to do something with user interaction or a broadcast receiver to trigger frequent operations without User Interaction...Cheers!
You can approach in this way
in the first time user install and start the application, you should store the current version as last_vertion_of_app in the shared preferences. then use a alarm Manager +broadcast receiver+service to check the manifest app version with shared preference stored version if both are different(not equal) that means some update happen. then you can do the thing what you want to happen if updated=true in the save service even without application starts.

Making a set up screen on first start up

I'm here today asking someone if they know a way to make a set up screen on first start up.
Here's the scenario: When someone downloads my app and uses it for the first time, it has to show a method where users make a password. On subsequent uses, I don't want it to be shown anymore. Does anybody know how to do this?
You can use the SharedPreferences for this purpose.
At the start of your application, check if the key "myKey+versioncode" is present or not in the SharedPreferences. If it not stored, then it means your application has not bee started yet, let the user create his/her password. Once the password is created, add the SharedPreferences "myKey+versioncode" with any value you like, and next time you will find this SharedPreferences, so it means the user already started the application and created its password.
However be careful about the "versionning" of this key, you might also want to keep a single key instead of one per version of your application.
Edit: Concept found at the time I was looking for EULA inplementation, here: Simple EULA implementation for Android

Categories

Resources