获取 APP versionName @param packageName 应用包名 @return versionName
(final String packageName)
| 262 | * @return versionName |
| 263 | */ |
| 264 | public static String getVersionName(final String packageName) { |
| 265 | if (TextUtils.isEmpty(packageName)) return null; |
| 266 | try { |
| 267 | // 执行 shell |
| 268 | ShellUtils.CommandResult result = ShellUtils.execCmd( |
| 269 | "dumpsys package " + packageName + " | grep version", |
| 270 | true |
| 271 | ); |
| 272 | if (result.isSuccessWithSuccessOutput()) { |
| 273 | String[] arrays = result.successMsg.split(DevFinal.REGEX.SPACE); |
| 274 | for (String value : arrays) { |
| 275 | if (!TextUtils.isEmpty(value)) { |
| 276 | try { |
| 277 | String[] splitArray = value.split("="); |
| 278 | if (splitArray.length == 2) { |
| 279 | if ("versionName".equalsIgnoreCase(splitArray[0])) { |
| 280 | return splitArray[1]; |
| 281 | } |
| 282 | } |
| 283 | } catch (Exception ignored) { |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | } catch (Exception e) { |
| 289 | LogPrintUtils.eTag(TAG, e, "getVersionName"); |
| 290 | } |
| 291 | return null; |
| 292 | } |
| 293 | |
| 294 | // ============ |
| 295 | // = 安装、卸载 = |
nothing calls this directly
no test coverage detected