Skip to content

Commit

Permalink
[feat] 알림권한 요청
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook123 committed Dec 11, 2023
1 parent 727adc5 commit 6a91cc0
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.go.sopt.winey.presentation.main

import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import androidx.activity.viewModels
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import androidx.fragment.app.replace
Expand Down Expand Up @@ -38,6 +43,8 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

requestNotificationPermission()

// 위니피드, 마이페이지 프래그먼트에서 getUserState 관찰
mainViewModel.getUser()
mainViewModel.patchFcmToken()
Expand All @@ -50,6 +57,20 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
showSuccessSnackBar()
}

private fun requestNotificationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PackageManager.PERMISSION_DENIED == ContextCompat.checkSelfPermission(
this,
Manifest.permission.POST_NOTIFICATIONS
)
) {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
CODE_NOTIFICATION_PERMISSION
)
}
}

private fun initNotiTypeHandler() {
when (notiType) {
KEY_RANKUP_TO_2, KEY_RANKUP_TO_3, KEY_RANKUP_TO_4 -> navigateToMyPageWithBundle(KEY_FROM_NOTI, true)
Expand Down Expand Up @@ -200,5 +221,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
private const val KEY_FEED_DELETE = "delete"
private const val KEY_PREV_SCREEN_NAME = "PREV_SCREEN_NAME"
private const val VAL_MY_FEED_SCREEN = "MyFeedFragment"

private const val CODE_NOTIFICATION_PERMISSION = 1020
}
}

0 comments on commit 6a91cc0

Please sign in to comment.