Skip to content

Commit

Permalink
fix: 알림 설정 이동 (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Aug 30, 2024
1 parent d761b8b commit 0e4334c
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class MyPageMenuViewModel @Inject constructor(
}

private fun handleNotificationMenu() {
reduce { copy(isCheckedNotification = !currentState.isCheckedNotification) }
navigateNotificationSetting()
// reduce { copy(isCheckedNotification = !currentState.isCheckedNotification) }
}

private fun handleNoticeMenu() {
Expand Down Expand Up @@ -113,4 +114,35 @@ class MyPageMenuViewModel @Inject constructor(
private fun showSnackBar(stringId: Int) {
postSideEffect { MenuSideEffect.ShowSnackBar(stringId) }
}

private fun navigateNotificationSetting() {
val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationSettingOreo(context)
} else {
notificationSettingOreoLess(context)
}
try {
context.startActivity(intent)
}catch (e: ActivityNotFoundException) {
e.printStackTrace()
}
}

@RequiresApi(Build.VERSION_CODES.O)
private fun notificationSettingOreo(context: Context): Intent {
return Intent().also { intent ->
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
}

private fun notificationSettingOreoLess(context: Context): Intent {
return Intent().also { intent ->
intent.action = "android.settings.APP_NOTIFICATION_SETTINGS"
intent.putExtra("app_package", context.packageName)
intent.putExtra("app_uid", context.applicationInfo?.uid)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
}
}

0 comments on commit 0e4334c

Please sign in to comment.