<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.moo.android.myApp"
android:versionCode="12"
android:versionName="1.2.37">
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();
}
2.
final Intent intent = new Intent(context, YourService.class);
final PendingIntent pending = PendingIntent.getService(context, 0, intent, 0);
final AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarm.cancel(pending);
long interval = 30000;//milliseconds
alarm.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),interval, pending);
本文介绍了一个 Android 应用如何实现版本检查功能,通过比较本地应用版本与服务器上的版本来判断是否需要更新。此外,还展示了如何设置定时任务以定期执行特定的服务操作。
7140

被折叠的 条评论
为什么被折叠?



