Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create manual versions

Tags:

android

Iam planning to create an app, and not to publish it at the google market. i want the users to update thire app once in a while when an updates will be rlsd via server(let's not get into the idea how i gonna do this)... so for this i need to give to each app some ID, so i know that that user gotta update his app, and not new installation (i wanna avoid the case the user will have two versions of the app).. and ofcourse install the app to new users. how could i sign those apps with version when i rls an update manually? mybe some other idea?

thanks, ray.

like image 824
rayman Avatar asked Apr 21 '10 16:04

rayman


1 Answers

You can use the android:versionCode and android:versionName attributes in the AndroidManifest.xml. That way, as long as the package name is the same it won't overlap and you can get that info like this to see if there is a newer version available:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="org.moo.android.myApp"
  android:versionCode="12"
  android:versionName="1.2.37">

Then you can read these values and compare with values on your server, like this:

try
{
    PackageManager manager = context.getPackageManager();
    PackageInfo info = manager.getPackageInfo("org.moo.android.myApp", 0);
    int code = info.versionCode;
    String name = info.versionName;

    // Compare with values on the server to see if there is a new version
}
catch(NameNotFoundException nnf)
{
    nnf.printStackTrace();
}

If you're checking for the version of the same app, you can replace the hard-coded package name with context.getPackageName().

like image 147
CaseyB Avatar answered Nov 19 '22 07:11

CaseyB