Reputation: 41
Is there any way to detect previous version of installed application in android.
For example I have one android application . In the previous version of this android application I have used UUID which is automatically generated . Now we have changed in the next version of this application and using ANDROID_ID at the place of UUID. Now suppose user upgrading application from older version to new version , In this case I want to detect that previous version of application is installed on phone or not and if it is installed what the version name of previous installed application.
Any help will be highly appreciated
Upvotes: 2
Views: 890
Reputation: 934
Since previous developer didn't update version names you might use last update time of the application. If it is older than it is required to be then update it.
PackageInfo class has lastUpdateTime attribute. Here how it can be used:
private Date getLastUpdateTime() {
PackageInfo pi;
try {
pi = getPackageManager().getPackageInfo(getPackageName(), 0);
Date resultdate = new Date(pi.lastUpdateTime);
return resultdate;
} catch (final NameNotFoundException e) {
return null;
}
}
Upvotes: 2
Reputation: 161
If your app was updated. Your old version was replaced. But shared preference have to stay (if user didn't clear app data).
Check if you could read UUID from shared preference YES new version NO old version. So you can approximately detect that version installed.
Upvotes: 0