views:

52

answers:

1

Hey,

We have a set of 3-5 android applications that we have developed for an enterprise to integrate with our back-end. How do we create an installer system that upgrades applications automatically. We were thinking of getting version numbers and querying the backend to get current versions and downloading them.

How do I get the version number of an application in Android?

ApplicationInfo info = getApplicationInfo();

try {
    info = getPackageManager().getApplicationInfo(info.packageName, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {

        e.printStackTrace();
    }

Any pointers will be most useful.

Thanks Sameer

A: 

Using the function below you can get the current Version Name or No for the application. This you can check against the to that of app at server side and if needed you can upgrade app.

public static function String getVersionName(Context context, Class cls) { try { ComponentName comp = new ComponentName(context, cls); PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0); return pinfo.versionName; } catch (android.content.pm.PackageManager.NameNotFoundException e) { return null; } }

success_anil
Thanks, works perfectly!
Sameer Segal