From 23aa3282dd0524e09e9ce99fccc8d6c5f305c064 Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Thu, 23 Jul 2026 09:34:28 +0000 Subject: [PATCH] Guide users to notification listener access --- .../notificationlog/ViewLogsFragment.kt | 23 +++++++++++++++++++ .../main/res/layout/fragment_view_logs.xml | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt b/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt index 457da53..2e4a63a 100644 --- a/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt +++ b/app/src/main/java/se/ajpanton/notificationlog/ViewLogsFragment.kt @@ -1,6 +1,9 @@ package se.ajpanton.notificationlog import android.os.Bundle +import android.content.ComponentName +import android.content.Intent +import android.provider.Settings import android.view.View import android.widget.TextView import androidx.fragment.app.Fragment @@ -11,6 +14,7 @@ import se.ajpanton.notificationlog.model.NotificationLogEntry import se.ajpanton.notificationlog.settings.LogField import se.ajpanton.notificationlog.settings.LogViewSettingsStore import se.ajpanton.notificationlog.settings.TimestampZone +import se.ajpanton.notificationlog.capture.NotificationCaptureService import java.text.DateFormat import java.util.Date @@ -20,6 +24,9 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) binding = FragmentViewLogsBinding.bind(view) + binding!!.notificationAccess.setOnClickListener { + startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)) + } binding!!.clearLogs.setOnClickListener { MaterialAlertDialogBuilder(requireContext()) .setTitle("Clear logs?") @@ -34,6 +41,15 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { loadLogs() } + override fun onResume() { + super.onResume() + binding?.notificationAccess?.text = if (isListenerEnabled()) { + "Notification access enabled" + } else { + "Enable notification access" + } + } + override fun onDestroyView() { binding = null; super.onDestroyView() } private fun loadLogs() { @@ -67,4 +83,11 @@ class ViewLogsFragment : Fragment(R.layout.fragment_view_logs) { if (zone == TimestampZone.UTC) format.timeZone = java.util.TimeZone.getTimeZone("UTC") return format.format(Date(value)) } + + private fun isListenerEnabled(): Boolean { + val manager = requireContext().getSystemService(android.app.NotificationManager::class.java) + return manager.isNotificationListenerAccessGranted( + ComponentName(requireContext(), NotificationCaptureService::class.java), + ) + } } diff --git a/app/src/main/res/layout/fragment_view_logs.xml b/app/src/main/res/layout/fragment_view_logs.xml index 93f31e2..f1065dd 100644 --- a/app/src/main/res/layout/fragment_view_logs.xml +++ b/app/src/main/res/layout/fragment_view_logs.xml @@ -1,6 +1,6 @@ -