package id.pribadi.qrisnotifier import android.app.Notification import android.content.ComponentName import android.os.Handler import android.os.Looper import android.service.notification.NotificationListenerService import android.service.notification.StatusBarNotification class NotifService : NotificationListenerService() { private val handler = Handler(Looper.getMainLooper()) private val tick = object : Runnable { override fun run() { Sender.flush(applicationContext) // coba kirim ulang antrean tiap 1 menit handler.postDelayed(this, 60_000) } } override fun onListenerConnected() { handler.removeCallbacks(tick) handler.post(tick) } override fun onListenerDisconnected() { handler.removeCallbacks(tick) requestRebind(ComponentName(this, NotifService::class.java)) } override fun onNotificationPosted(sbn: StatusBarNotification) { val pkg = sbn.packageName ?: return if (!Sender.allowed(this, pkg)) return val ex = sbn.notification.extras val title = ex.getCharSequence(Notification.EXTRA_TITLE)?.toString().orEmpty() val text = (ex.getCharSequence(Notification.EXTRA_BIG_TEXT) ?: ex.getCharSequence(Notification.EXTRA_TEXT))?.toString().orEmpty() if (text.isEmpty()) return // ringkasan grup / notifikasi kosong // Paket di luar daftar pantauan hanya lolos saat mode diagnosa -> ditandai diag (tidak diproses sebagai pembayaran) Sender.enqueue(this, pkg, title, text, sbn.postTime, diag = !Sender.inList(this, pkg)) Sender.flush(applicationContext) } }