Skip to content

Commit

Permalink
Ask for permission to post notifications (SDK 33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Heckel committed Nov 19, 2022
1 parent abeae71 commit 92ec2d7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28"/> <!-- Only required on SDK <= 28 -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/> <!-- To install packages downloaded through ntfy; craazyy! -->
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/> <!-- To reschedule the websocket retry -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <!-- As of Android 13, we need to ask for permission to post notifications -->

<application
android:name=".app.Application"
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.heckel.ntfy.ui

import android.Manifest
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.app.AlertDialog
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand All @@ -20,6 +22,7 @@ import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -208,6 +211,18 @@ class MainActivity : AppCompatActivity(), ActionMode.Callback, AddFragment.Subsc
schedulePeriodicPollWorker()
schedulePeriodicServiceRestartWorker()
schedulePeriodicDeleteWorker()

// Permissions
maybeRequestNotificationPermission()
}

private fun maybeRequestNotificationPermission() {
// Android 13 (SDK 33) requires that we ask for permission to post notifications
// https://developer.android.com/develop/ui/views/notifications/notification-permission

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

override fun onResume() {
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelog/29.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Bug fixes + maintenance:
* Upgrade Android dependencies to SDK 33 (no ticket)
* Android 13: Ask for permission to post notifications (#508)
* Remove timestamp when copying message text (#471, thanks to @wunter8)

Additional translations:
Expand Down

0 comments on commit 92ec2d7

Please sign in to comment.