IThe scenario is that my application search all installed application in order to determine versions of those applications. Then store name of the application with its versions on the same file. If new version of the application is available, then give notification to the user. The question is "how can I learn the version of the other application from my application ?"
Thanks for all your help
Something like this should work to get the current version:
List<PackageInfo> packages = getPackageManager().getInstalledPackages();
for(int i=0;i<packages.size();i++)
{
int version = packages.get(i).versionCode;
// do whatever with it here
}
Getting the most recent version in the Play Store doesn't really work, though. Like A--C said, you could check versionName instead, and just notify as updated if the two aren't exactly the same(don't worry about higher/lower, just inequality).
You can do following (inside of Activity or any other Context)
getPackageManager().getPackageInfo(getPackageName(), 0).versionName
getPackageManager().getPackageInfo(getPackageName(), 0).versionCode
Related
I know we can define a custom permission in one app and other app can ask for this permission using uses_permission tag.
My problem is, I have 2 apps and one app is dependent on other to work as expected. As both the apps will be updated from play store over time, their versions has to be in sync so that they can interact and work without any issues.
User should be able to install/update app B to version 2 only if they have already installed/updated version 2 of app A.
My idea is, if this can be handled by defining something (uses_feature where we can define version also, just like glesVersion) in manifest file itself, then user will not see update available of app B, if they have not updated app A already.
I hope I have explained my problem clearly. Please suggest some solution.
While opening your launcher activity all you ought to do is check
the version of that package you have installed and then show them the
update.
You need to figure out what is the right package name of your installed application on your device.
Getting Package Info:
PackageInfo pinfo = null;
pinfo = getPackageManager().getPackageInfo("com.yourapplication.android", 0);
//getVersionCode is Deprecated, instead use getLongVersionCode().
long verCode = pinfo.getLongVersionCode();
//getVersionName is Deprecated, instead use versionName
String verName = pinfo.versionName;
Then you can check in here like,
if(verName.contentEquals("your new version") {
// do something such as update
}
else {
// function normally
}
Hope it helps!
I am trying to figure out how to forcefully update the latest version from play store.
As the older version of my android app is already in play store where i haven't implement the check to get the current version of the app and compare with the play store app version like specified in the link update android app forcefully
I want that when I upload my new version on play store then user should not be able to use the app till he update the new version.
Could you please help me out.
I have to do the same thing but what i did i gonna share you i hope this will help you.
1> I get the previous code version of my application and store it the string.xml. like my live app version code is 1. And my new app version code is 1.1.
This code is tell us our app version code.
PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
int versionNumber = pinfo.versionCode;
String versionName = pinfo.versionName;
2> Than check
if (newcodeversion > previouscodeversion) {
// open any activity or pop up
}
3> And in the new activity place Text view with text "you have update version" and a button.And on the click of that button navigate to google play store.
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("Your application URL"));
startActivity(i);
It is not possible if the logic of comparing the versionCode and blocking the user isn't already placed inside the current app on PlayStore.
This is not difficult to do. Simply bar the user from having the core functionality of what ever your app is responsible for.
Example, if it is a calling app, do a version check, and if the user has not updated as yet, restrict the use of call making entirely.
According to #pieter-b, taken from Forcing Updates:
For this to work, some kind of logic the app uses needs to be under your control. And then without that part of logic the app won't work
and you can show a message: "your app is out of date, please download
the new version to continue use."
Consider a messenger app where traffic goes through your servers. Just
refuse to deliver messages of clients using an outdated version.
Also refer to Force update android app when new version available.
It's possible to get if an app is currently installed on the sd-card or not, by using the next code, using the ApplicationInfo flags :
final boolean isInstalledOnExternalStorage=(applicationInfo.flags&ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0;
However, what I'd like to know is how to get the requested installation location as specified by the manifest (described here) of an installed app.
Sadly, as much as I've read here and on the documentation, I can't find out where this attribute's values can be fetched, unless maybe I'd need to parse the APK file myself...
So, how do I achieve it? Is it even possible using the normal Android framework?
Look at this code, it works in my app:
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(mPackageName, 0);
if (packageInfo.installLocation != PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY) {
.....
}
http://developer.android.com/reference/android/content/pm/PackageInfo.html#installLocation
was introduced in API 21
But this field exists even in Android 2.3
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3_r1/android/content/pm/PackageInfo.java/
I will be releasing an update for my app with a new data structure, therefore if a user is updating my app I need to update their current data. So I was wondering how can I programatically check if the user updated my app or installed a new copy (if a new copy is installed I don't need to update anything) ?
SQLite
If your data is in an SQLite database, you can implement code in SQLiteOpenHelper.onUpgrade().
Checking previous version
If not, you need some kind of way to check the previous version that was open on the device. Something like:
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
// Use SharedPreferences to store something like "LAST_VERSION_RUN" = pInfo.versionName
Then, you can check if previous version is not equal to current version. Of course, this kind of code has to be in previous versions, also. There is no way to implement, once an app is already in the wild, a code that will detect whether an app has been upgraded.
Checking current version
I suppose what you could do in this case is detect the app version, and then set a flag to not update the data schema again. So, let's say your app version was 1.0.2, and is now 1.0.3:
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
if (pInfo.versionName.equals("1.0.3") && /* some SharedPreference value */ == false) {
// upgrade
// set SharedPreference value to true
}
I think that's going to be the best way to implement this if you're not using SQLite.
Is there anyway to notify the users (inside of my application) if newer versions is published? perhaps through Dialog?
Usually in web client android application we make a request to the server for getting the current version.
Use
String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0 ).versionName;
And compare and notify the user with a dialog.
Santosh's solution just allow you to access to the "android:versionName" attribute in your manifest.
look at Android Market Application Updates.
It could help you