现在的位置: 首页 > 综合 > 正文

rom中,内置应用升级

2017年09月05日 ⁄ 综合 ⁄ 共 1191字 ⁄ 字号 评论关闭

当在rom中,内置了自己的应用,需要升级时。需要注意应用版本号的书写方式:一定要是正确的数字形式。

另,要注意versionCode和versionName,其中,versionCode要与内置的版本不同,且大于内置版本。versionName可以为自定义字符。

原因:转自:http://orgcent.com/android-system-app-update-restore/

Android系统内置应用更新或升级后被还原的原因

如果更新或者升级后系统内置应用,遇到重启Android系统后内置应用被还原,那是因为手动安装的APK版本号和系统内置API版本号一样。

1、Android系统应用更新机制
系统为每个应用在AndroidMainfest.xml提供了versionName、versionCode两个属性。
versionName:String类型,用来给应用的使用者来查看版本.
versionCode:Integer类型,作为系统判断应用是否能升级的依据。

2、Android系统内置应用更新判断代码
代码来自frameworks/base/services/java/com/android/server/PackageManagerService.java 中 scanPackageLI函数的package更新判断条件(约第2580-2621行附近)

// First check if this is a system package that may involve an update
if (updatedPkg != null && (parseFlags&PackageParser.PARSE_IS_SYSTEM) != 0) {
    if (!ps.codePath.equals(scanFile)) {
      // The path has changed from what was last scanned...  check the
      // version of the new path against what we have stored to determine
      // what to do.
      if (pkg.mVersionCode < ps.versionCode) {
          // The system package has been updated and the code path does not match
          // Ignore entry. Skip it.

从上面代码注释可以知道:更新系统内置应用时,如果新的versionCode没有大于当前安装的版本,更新将被忽略。

3、开发者误区
对Android应用更新机制不熟悉的开发者,错误地把versionName作为应用更新的依据,以致于在更新程序出现一些问题:
1、更新程序设计时必须把versionName设置小数形式,如2.1,当设置为2.2.1时程序就不好判断是否该更新版本。
2、可能导致系统内置应用无法升级,不断被还原。

抱歉!评论已关闭.