MCPcopy Create free account
hub / github.com/afkT/DevUtils / getVersionName

Method getVersionName

lib/DevApp/src/main/java/dev/utils/app/ADBUtils.java:264–292  ·  view source on GitHub ↗

获取 APP versionName @param packageName 应用包名 @return versionName

(final String packageName)

Source from the content-addressed store, hash-verified

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 // = 安装、卸载 =

Callers

nothing calls this directly

Calls 6

execCmdMethod · 0.95
eTagMethod · 0.95
isEmptyMethod · 0.45
splitMethod · 0.45
equalsIgnoreCaseMethod · 0.45

Tested by

no test coverage detected