diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 8334af4a..39ff12e9 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,7 @@
+
@@ -20,13 +21,11 @@
+ android:theme="@style/AppTheme">
-
= Build.VERSION_CODES.TIRAMISU) {
+ notificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
+ }
}
}
+ private val notificationPermissionLauncher = registerForActivityResult(
+ ActivityResultContracts.RequestPermission()
+ ) { isGranted: Boolean ->
+ if (isGranted) enablePullNotifications(this)
+ }
+
// Checks if the activity was launched from a notification from another account than the
// current active one, and if so switches to that account
private fun notificationFromOtherUser(): Boolean {
diff --git a/app/src/main/java/org/pixeldroid/app/utils/notificationsWorker/NotificationsWorker.kt b/app/src/main/java/org/pixeldroid/app/utils/notificationsWorker/NotificationsWorker.kt
index af1d924e..0637f796 100644
--- a/app/src/main/java/org/pixeldroid/app/utils/notificationsWorker/NotificationsWorker.kt
+++ b/app/src/main/java/org/pixeldroid/app/utils/notificationsWorker/NotificationsWorker.kt
@@ -1,12 +1,15 @@
package org.pixeldroid.app.utils.notificationsWorker
+import android.Manifest
import android.app.NotificationChannel
import android.app.NotificationChannelGroup
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
+import android.content.pm.PackageManager
import android.os.Build
+import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.work.CoroutineWorker
@@ -143,7 +146,10 @@ class NotificationsWorker(
)
with(NotificationManagerCompat.from(applicationContext)) {
- notify(uniqueUserId.hashCode(), groupBuilder.build())
+ if (ActivityCompat.checkSelfPermission(applicationContext,
+ Manifest.permission.POST_NOTIFICATIONS
+ ) == PackageManager.PERMISSION_GRANTED
+ ) notify(uniqueUserId.hashCode(), groupBuilder.build())
}
}
@@ -216,7 +222,10 @@ class NotificationsWorker(
with(NotificationManagerCompat.from(applicationContext)) {
// notificationId is a unique int for each notification
- notify((uniqueUserId + notification.id).hashCode(), builder.build())
+ if (ActivityCompat.checkSelfPermission(applicationContext,
+ Manifest.permission.POST_NOTIFICATIONS
+ ) == PackageManager.PERMISSION_GRANTED
+ ) notify((uniqueUserId + notification.id).hashCode(), builder.build())
}
}