diff --git a/.gitignore b/.gitignore index 0fdf901..f4fcb6c 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,7 @@ app/google-services.json *.jks keystore.properties *.aab +output-metadata.json +**/output-metadata.json +*.zip +*.apk diff --git a/app/src/main/java/com/dkin/chevit/app/MainActivity.kt b/app/src/main/java/com/dkin/chevit/app/MainActivity.kt index c3eaa0d..9844622 100644 --- a/app/src/main/java/com/dkin/chevit/app/MainActivity.kt +++ b/app/src/main/java/com/dkin/chevit/app/MainActivity.kt @@ -1,7 +1,16 @@ package com.dkin.chevit.app +import android.Manifest.permission.POST_NOTIFICATIONS +import android.content.Intent +import android.content.pm.PackageManager.PERMISSION_GRANTED +import android.net.Uri +import android.os.Build +import android.provider.Settings import android.view.MenuItem import android.view.inputmethod.InputMethodManager +import androidx.activity.result.contract.ActivityResultContracts.RequestPermission +import androidx.appcompat.app.AlertDialog +import androidx.core.content.ContextCompat import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.NavigationUI @@ -9,6 +18,7 @@ import androidx.navigation.ui.navigateUp import com.dkin.chevit.app.databinding.ActivityMainBinding import com.dkin.chevit.core.base.BaseActivity import dagger.hilt.android.AndroidEntryPoint +import timber.log.Timber @AndroidEntryPoint class MainActivity : BaseActivity(ActivityMainBinding::inflate) { @@ -27,6 +37,12 @@ class MainActivity : BaseActivity(ActivityMainBinding::infl navHostFragment.navController } + private val requestPermissionLauncher by lazy { + registerForActivityResult(RequestPermission()) { isGranted: Boolean -> + Timber.d("Permission granted: $isGranted") + } + } + override fun initView() { NavigationUI.setupActionBarWithNavController( this@MainActivity, @@ -37,6 +53,9 @@ class MainActivity : BaseActivity(ActivityMainBinding::infl hideSoftKeyboard() } supportActionBar?.hide() + + // TODO 임시로 이렇게 처리 추후 개선 필요 + askNotificationPermission() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -63,4 +82,35 @@ class MainActivity : BaseActivity(ActivityMainBinding::infl val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? inputMethodManager?.hideSoftInputFromWindow(focus.windowToken, 0) } + + private fun askNotificationPermission() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + if (ContextCompat.checkSelfPermission(this, POST_NOTIFICATIONS) == PERMISSION_GRANTED) { + // 이미 알림 권한 허용 + return + } else if (shouldShowRequestPermissionRationale(POST_NOTIFICATIONS)) { + AlertDialog.Builder(this) + .setTitle("기기 알림이 꺼져있어요") + .setMessage("알림을 허용하여 준비물을 빼먹지 않도록 해요!") + .setPositiveButton("확인") { _, _ -> + navigateNotificationSetting() + } + .setNegativeButton("취소") { _, _ -> } + .show() + } else { + requestPermissionLauncher.launch(POST_NOTIFICATIONS) + } + } + } + + private fun navigateNotificationSetting() { + val intent = Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply { + putExtra(Settings.EXTRA_APP_PACKAGE, packageName) + } + kotlin.runCatching { + startActivity(intent) + }.onFailure { throwable -> + Timber.e(throwable) + } + } } diff --git a/presentation/notification/build.gradle.kts b/presentation/notification/build.gradle.kts index f27495c..d6cfc9b 100644 --- a/presentation/notification/build.gradle.kts +++ b/presentation/notification/build.gradle.kts @@ -13,6 +13,7 @@ android { dependencies { implementation(project(":core")) implementation(project(":domain")) + implementation(project(":presentation:resource")) implementation(platform(libs.firebase.bom)) implementation(libs.firebase.messaging) diff --git a/presentation/notification/src/main/AndroidManifest.xml b/presentation/notification/src/main/AndroidManifest.xml index 910b067..2391bca 100644 --- a/presentation/notification/src/main/AndroidManifest.xml +++ b/presentation/notification/src/main/AndroidManifest.xml @@ -1,8 +1,17 @@ + + + + +