Skip to content

Commit

Permalink
⚡️ :: 인 앱 업데이트 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
parkuiery committed Jun 5, 2024
1 parent 9e6b5ed commit 7d539fc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/src/main/java/team/aliens/dms/android/app/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSiz
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.core.view.WindowCompat
import com.google.accompanist.adaptive.calculateDisplayFeatures
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.UpdateAvailability
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.StateFlow
import team.aliens.dms.android.core.designsystem.DmsTheme
Expand All @@ -30,6 +33,7 @@ class MainActivity : ComponentActivity() {
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
)

checkAppUpdate()
setContent {
val windowSizeClass = calculateWindowSizeClass(activity = this)
val displayFeatures = calculateDisplayFeatures(activity = this)
Expand All @@ -43,4 +47,23 @@ class MainActivity : ComponentActivity() {
}
}
}

private fun checkAppUpdate() {
val appUpdateManager = AppUpdateManagerFactory.create(this)
val appUpdateInfoTask = appUpdateManager.appUpdateInfo

appUpdateInfoTask.addOnSuccessListener { appUpdateInfo ->
val isUpdateAvailable =
appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE

if (isUpdateAvailable && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
appUpdateManager.startUpdateFlowForResult(
appUpdateInfo,
AppUpdateType.IMMEDIATE,
this,
0,
)
}
}
}
}

0 comments on commit 7d539fc

Please sign in to comment.