Skip to content

Commit 5d93955

Browse files
author
Lyor Goldstein
committed
Fixed package version code extraction according to current API level
1 parent 9b1b971 commit 5d93955

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
@@ -229,7 +229,10 @@ public String getVersionCode() {
229229
try {
230230
PackageManager pm = this.context.getPackageManager();
231231
PackageInfo pkgInfo = pm.getPackageInfo(getPackageName(), 0);
232-
versionCode = "" + pkgInfo.versionCode;
232+
versionCode = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
233+
? Long.toString(pkgInfo.getLongVersionCode())
234+
: Integer.toString(pkgInfo.versionCode)
235+
;
233236
} catch (PackageManager.NameNotFoundException e) {
234237
}
235238
}
@@ -249,7 +252,7 @@ public String getVersionName() {
249252
return versionName != null ? versionName : "";
250253
}
251254

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

0 commit comments

Comments
 (0)