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.
Related
For example I expect this kind of situation: data in my application lost relevance and so it usless until update. And until update it have to show users some predefined message.
Is here any simple and free solution to this task?
Guess I can use some server to somehow send simple messages... but it sounds way too complicated.
If this is important I use Xamarin.
Update: main difficulty here is fact - my application can't in any way define if it's outdated or not. This may happen in random moment.
Although the requirement is not very clear I assume Update here means app update.
each time user launches app make call to an api on ur server to check if user needs to update app
If that returns true take user to a static view that says app needs update and redirects user to google play to install updates
If you want to avoid using a server, you should try Firebase (https://firebase.google.com/). More specifically, you should use Firebase Remote Config (https://firebase.google.com/features/remote-config/).
Define in a key-value pair of something like minimum_app_version_required in Firebase Remote Config. Every time user opens the your app, compare the values of app version and minimum_app_version_required that you are getting from Firebase console and show a dialog box accordingly. You can also change the value of minimum_app_version_required anytime you want.
Just set some internal flag. That when that situation occurs, you can set the flag to true and just edit whatever layout element you are using such as listView or any other element with your predefined messages saved in strings.xml. You can also build any custom pop up screen, depends how you want to show them. Let me know if you didn't understand or exactly how you want?
Need to implement versioning for this problem. To achieve this, you have to maintain a version number in server, this is the version number you app will have to save and use it to validate with server. If both are not same, then app will get the latest data from the server.
I am programming a feature inside my app that syncs all the users favorites to Google Drive. The whole point of this feature is that all the devices of that user are in-sync.
There are somethings that are good to know:
Is that the app pulls all the favorites from Google Drive at the startup, compares them with the local favorites. If there is a favorite inside the Google Drive folder that isn't there on the local storage, that favorite gets added to the local storage, and vice-versa.
The app uses the Google Drive API.
The problem with the first point above is the way of comparing cloud and local storage. When the user removes a favorite, and the connection is bad, the favorite isn't removed on Google Drive. When launching the app that same favorite gets added again.
The app can't be launched while offline so a favorite can't be removed offline.
I am thinking of a way to make some kind of 'changelog' to see that a favorite is removed or added, that contains the time that it has been added/removed, and somekind of device id. (I am thinking out loud now) A problem of this is that the changelog file gets quite large when using the app for a while (every favorite addition and removal is logged)
The problem that I am facing is not the code, but the way the syncing needs to work and check for favorites. I've tried submitting the favorites themselves to Google Drive, but that takes up to much space (and can't be debugged easily).
Please think out loud (in the comments haha), I am not sure how I would tackle this challenge and I need to be pointed in the correct direction by someone.
Any solution is welcome.
Change Subscriptions
allows your application to receive ChangeEvents even when it is not running. For example your application could show a notification when a file or folder it cares about has changed, even if that change occurs while your application not running.
The following example code shows the logic you might implement to add a change subscription to a file:
DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient,
mSelectedFileId);
file.addChangeSubscription(mGoogleApiClient);
Handle change subscriptions events
To handle change subscription events you must create a class that extends DriveEventService and overrides the onChange method. This is where application-specific processing of the ChangeEvent would occur.
public class MyDriveEventService extends DriveEventService {
#Override
public void onChange(ChangeEvent event) {
Log.d(TAG, event.toString());
// Application-specific handling of event.
}
}
Add this to your AndroidManifest.xml file
<application ...>
...
<service android:name=".MyDriveEventService" android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.drive.events.HANDLE_EVENT"/>
</intent-filter>
</service>
</application>
Your application will receive a ChangeEvent whenever an file or folder gets updated by another application on the device or the Drive API downloads changes from the server.
You can also try using Push Notifications (Drive Rest API):
The Drive API provides push notifications that let you watch for changes to resources. You can use this feature to improve the performance of your application. It allows you to eliminate the extra network and compute costs involved with polling resources to determine if they have changed. Whenever a watched resource changes, the Drive API notifies your application.
You can read the blog for push notification for more information.
Hope this helps!
I'm making an app for Android that will not be in the Play Store and I was wondering if I could make it ask to update the app when I have an update ready. Also, would I be able to push the update out just by uploading to Mediafire, or would I need my own server? Thanks!
You will need to create a web service for it, which you can update after releasing new version. You can use this web serive in your app to check whethet the new version is out or not. Hope this helps.
As beserk answered .. i think i'll explain more in detail,though i'm not sure that this is the procedure that should be used ,but this is how i would do it .. make your app talk to a server once in 15 days or something so that it can check for a value in the server .. in your app get that value and is there is an update of the app according to your server ,just redirect to an another activity in the app so that user may not able to use your app again or keep a shared preference in the app like update=true and just check the shared pref value during the splash screen ,now redirect it another activity saying you need to update the app in order to use it ... i'm sure that there will be lot of other ways ,but this is the way i would do it
I have a app on play store and i want to provide app update through the play store.
Also, on updation of the app i want to perform some task. So, how can i perform a task on updation of my app from the play store.
I thought of maintaining current version and cross check it every time the app is fired, is there any other efficient way such as any intent fired on app updation that can be handled on the device itself.
You can save your current version code in shared preferences and on upgrade, cross check the new version with the previously stored one.
if (savedVersionCode < currentVersionCode) {
.
.
//PERFORM CERTAIN TASKS...
.
.
}
You can do this in your application's onCreate() or simply in you launcher activity's onCreate() if you have only one entry point.
The current version idea is a solid one. Just store it in the shared preferences and read it from there. It isn't really slow so the "negative" impact on performance can be simply ignored.
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.