Skip to content

Commit f5640e6

Browse files
author
Lyor Goldstein
committed
Fixed package version code extraction according to current API level
1 parent 562ddbc commit f5640e6

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

logback-android/src/main/java/ch/qos/logback/core/android/AndroidContextUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ public String getVersionCode() {
228228
try {
229229
PackageManager pm = this.context.getPackageManager();
230230
PackageInfo pkgInfo = pm.getPackageInfo(getPackageName(), 0);
231-
versionCode = "" + pkgInfo.versionCode;
231+
versionCode = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
232+
? Long.toString(pkgInfo.getLongVersionCode())
233+
: Integer.toString(pkgInfo.versionCode)
234+
;
232235
} catch (PackageManager.NameNotFoundException e) {
233236
}
234237
}
@@ -248,7 +251,7 @@ public String getVersionName() {
248251
return versionName != null ? versionName : "";
249252
}
250253

251-
private String absPath(File file) {
254+
private static String absPath(File file) {
252255
return file != null ? file.getAbsolutePath() : "";
253256
}
254257
}

0 commit comments

Comments
 (0)