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.
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()
.
I wouldn't worry about signing them per say, why not just have a value in the strings.xml file that has the version number? A simply check against the value on the server could determine whether an update is necessary.
精彩评论