Skip to content

Commit

Permalink
Merge pull request #317 from team-peekabook/feature/#316-request-noti…
Browse files Browse the repository at this point in the history
…fication-permission

#316 [feat] 안드로이드 13 이상 버전에서 알림 권한 요청하는 로직 구현
  • Loading branch information
2zerozu authored Mar 30, 2024
2 parents 618012c + 4b1e89f commit 28d4c28
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
<uses-feature
android:name="android.hardware.camera"
android:required="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission
android:name="android.permission.POST_NOTIFICATIONS"
android:minSdkVersion="33" />

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/sopt/peekabookaos/PeekaMessageService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class PeekaMessageService : FirebaseMessagingService() {
}

companion object {
const val CHANNEL_ID = "peeka_channel"
const val NOTIFICATION_ID = 1
const val CHANNEL_NAME = "peeka_channel_name"
const val TITLE = "title"
const val BODY = "body"
private const val CHANNEL_ID = "peeka_channel"
private const val NOTIFICATION_ID = 1
private const val CHANNEL_NAME = "peeka_channel_name"
private const val TITLE = "title"
private const val BODY = "body"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.sopt.peekabookaos.presentation.main

import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import androidx.activity.addCallback
import androidx.activity.viewModels
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
Expand All @@ -17,12 +22,30 @@ import timber.log.Timber
@AndroidEntryPoint
class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {
private val mainViewModel: MainViewModel by viewModels()
private val notificationPermissionRequestCode = 101

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.vm = mainViewModel
initBottomNavigationView()
clickBackPressedButton()
checkAndRequestNotificationPermission()
}

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

private fun initBottomNavigationView() {
Expand Down

0 comments on commit 28d4c28

Please sign in to comment.