feat: add notification-access setting item with jump

This commit is contained in:
2026-08-16 18:12:06 +08:00
parent 8e722dc545
commit e2a289a4b0
3 changed files with 64 additions and 2 deletions
@@ -1,8 +1,10 @@
package top.yeij.hearth
import android.app.Activity
import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import android.provider.Settings
import android.text.TextUtils
import android.util.Log
import android.view.View
@@ -24,6 +26,7 @@ import top.yeij.hearth.webapp.Tab
import top.yeij.hearth.webapp.WebAppContainer
import top.yeij.hearth.webapp.WebAppRepository
import top.yeij.hearth.webview.JsBridge
import top.yeij.hearth.webview.NotificationAccessProvider
import top.yeij.hearth.webview.WebAppHost
import top.yeij.hearth.webview.WebViewManager
import java.io.File
@@ -47,6 +50,19 @@ class MainActivity : Activity() {
private val webAppContainer = WebAppContainer()
private val gson = Gson()
private val webAppHost = WebAppHostImpl()
// 通知使用权访问实现:检查授权状态 + 跳转系统授权页(供设置页授权项使用)
// Notification-access implementation: check grant state + jump to system settings
// (used by the settings permission item)
private val notificationAccess = object : NotificationAccessProvider {
override fun isGranted(): Boolean =
NotificationManagerCompat.getEnabledListenerPackages(this@MainActivity)
.contains(packageName)
override fun requestAccess() {
startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS))
}
}
private lateinit var mediaSource: MediaSessionSource
private lateinit var root: FrameLayout
private lateinit var desktopWebView: WebView
@@ -91,6 +107,7 @@ class MainActivity : Activity() {
webAppContainer = webAppContainer,
webAppHost = webAppHost,
postToMainThread = { desktopWebView.post(it) },
notificationAccess = notificationAccess,
)
root = FrameLayout(this)
setContentView(root)