Guide users to notification listener access
This commit is contained in:
@@ -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),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user