-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
248676e
commit f7e72e2
Showing
4 changed files
with
23 additions
and
20 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/src/main/kotlin/cn/super12138/todo/utils/VersionUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cn.super12138.todo.utils | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
|
||
object VersionUtils { | ||
fun getAppVersion(context: Context): String { | ||
val pkgInfo = context.packageManager.getPackageInfo(context.packageName, 0) | ||
val verName = pkgInfo.versionName | ||
val verCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { | ||
pkgInfo.longVersionCode.toInt() | ||
} else { | ||
pkgInfo.versionCode | ||
} | ||
return "$verName($verCode)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters