안드로이드 버젼 관리: 두 판 사이의 차이
둘러보기로 이동
검색으로 이동
편집 요약 없음 |
(안드로이드 버젼 가져오기) |
||
| 20번째 줄: | 20번째 줄: | ||
소스 |
소스 |
||
<source lang="kotlin"> |
<source lang="kotlin"> |
||
fun getAppVersionInfo(context: Context): Pair<Int, String> { |
|||
| ⚫ | |||
return try { |
|||
| ⚫ | |||
// For API 33 (Android 13) and above, use 'longVersionCode' |
// For API 33 (Android 13) and above, use 'longVersionCode' |
||
// For compatibility across all APIs, use 'versionCode' and cast as needed |
// For compatibility across all APIs, use 'versionCode' and cast as needed |
||
val versionCode = packageInfo.versionCode // Deprecated but widely compatible |
val versionCode = packageInfo.versionCode // Deprecated but widely compatible |
||
val versionName = packageInfo.versionName |
val versionName = packageInfo.versionName |
||
Pair(versionCode, versionName) |
|||
} catch (e: PackageManager.NameNotFoundException) { |
|||
e.printStackTrace() |
|||
Pair(0, "N/A") |
|||
} |
|||
} |
|||
</source> |
</source> |
||
2025년 12월 29일 (월) 01:41 기준 최신판
안드로이드 버젼관리
build.gradle.kts
android {
// ... other configurations like compileSdk, namespace, etc.
defaultConfig {
applicationId = "com.example.myapp"
minSdk = 24
targetSdk = 34 // Example target SDK
versionCode = 1 // Internal version number (integer)
versionName = "1.0.0" // User-visible version string
}
// ... other build types
}
소스
fun getAppVersionInfo(context: Context): Pair<Int, String> {
return try {
val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
// For API 33 (Android 13) and above, use 'longVersionCode'
// For compatibility across all APIs, use 'versionCode' and cast as needed
val versionCode = packageInfo.versionCode // Deprecated but widely compatible
val versionName = packageInfo.versionName
Pair(versionCode, versionName)
} catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace()
Pair(0, "N/A")
}
}