Reputation: 822
I am programming an update for an App. A pop-up will appear at the beginning when the app is started for the first time. But it will just happen if the Update was installed as an Update.
Whoever install the app as a new installation should not see the pop-up.
The previous version of the App can't commit any SharedPreferences XML.
If you dont understand the situation, ask for further details, please.
Upvotes: 0
Views: 805
Reputation: 39255
Creating a BroadcastReceiver that listens to the ACTION_PACKAGE_REPLACED Intent will do the job.
You just put this in your manifest
<receiver android:name=".OnUpgradeReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" android:path="your.app.package" />
</intent-filter>
</receiver>
Upvotes: 0
Reputation: 9945
In the onCreate() of your launcher activity, check if a file with a name of your choice exists, like "INSTALLED", for example.
A safer (multi-activity safe) approach would be to place this test in the onCreate() of your application and place the result of the test in a static variable in your application. This way, whichever activity is launched via any intent (launcher or not), you can retrieve the static field from the application object.
Upvotes: 1
Reputation: 12823
I am doing that very thing and I've also included some Google Analytics events in the mix so I track upgrades vs. new installs and can see them over time ;)
// Display Recent Changes on 1st use of new version
if (!appPrefs.getAppVer().equals(getAppVerName())) {
if (appPrefs.getAppVer().equals("")) {
tracker.trackEvent("Application", "Install", getAppVerName(), 1);
} else if (!appPrefs.getAppVer().equals("N/A")) {
tracker.trackEvent("Application", "Upgrade", appPrefs.getAppVer().toString()+"->"+getAppVerName(), 1);
}
// display recent changes dialog
tracker.trackPageView("/RecentChanges");
appPrefs.saveAppVer(getAppVerName());
appPrefs.saveAcceptedUsageAggrement(false);
}
// Display Usage Agreement on 1st use of new version
if (!appPrefs.getAcceptedUsageAggrement()) {
tracker.trackPageView("/UsageAgreement");
// display usage agreement dialog
// negative button actions here
appPrefs.saveAppVer("N/A");
// positive button actions here
appPrefs.saveAcceptedUsageAggrement(true);
}
More details at my blog: http://www.aydabtudev.com/2011/03/google-analytics-tricks-for-android.html
Upvotes: 1
Reputation: 1544
You can register for a broadcast by the system. On update of an app, the system sends the intent ACTION_PACKAGE_REPLACED.
Upvotes: 0