From bdd264aa6ad03bb0a4f218113e0bb21ea303926d Mon Sep 17 00:00:00 2001 From: kaajjo Date: Tue, 6 Aug 2024 18:08:56 +0300 Subject: [PATCH] fix: request `POST_NOTIFICATIONS` permission --- .../byedpi/activities/MainActivity.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/src/main/java/io/github/dovecoteescapee/byedpi/activities/MainActivity.kt b/app/src/main/java/io/github/dovecoteescapee/byedpi/activities/MainActivity.kt index 58b1cd1..99b67da 100644 --- a/app/src/main/java/io/github/dovecoteescapee/byedpi/activities/MainActivity.kt +++ b/app/src/main/java/io/github/dovecoteescapee/byedpi/activities/MainActivity.kt @@ -1,10 +1,12 @@ package io.github.dovecoteescapee.byedpi.activities +import android.Manifest import android.annotation.SuppressLint import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.content.pm.PackageManager import android.net.VpnService import android.os.Build import android.os.Bundle @@ -14,6 +16,7 @@ import android.view.MenuItem import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import androidx.lifecycle.lifecycleScope import io.github.dovecoteescapee.byedpi.R import io.github.dovecoteescapee.byedpi.data.AppStatus @@ -154,6 +157,15 @@ class MainActivity : AppCompatActivity() { val theme = getPreferences(this) .getString("app_theme", null) SettingsFragment.setTheme(theme ?: "system") + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && + ContextCompat.checkSelfPermission( + this, + Manifest.permission.POST_NOTIFICATIONS + ) != PackageManager.PERMISSION_GRANTED + ) { + requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), 1) + } } override fun onResume() {