package com.rgt.superr.business.push.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import com.rgt.superr.bean.push.NotificationSendBean
import com.rgt.superr.bean.push.NotificationSendBean.Companion.POPUP_WHERE_PACKAGE
import com.rgt.superr.business.push.notification.MyNotificationManager


class PackageReceiver : BroadcastReceiver() {

    companion object {
        fun register(context: Context) {
            val intentFilter = IntentFilter().apply {
                addAction(Intent.ACTION_PACKAGE_REMOVED)
                addAction(Intent.ACTION_PACKAGE_ADDED)
                addDataScheme("package")
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                context.registerReceiver(PackageReceiver(), intentFilter, Context.RECEIVER_EXPORTED)
            } else {
                context.registerReceiver(PackageReceiver(), intentFilter)
            }
        }
    }

    override fun onReceive(context: Context, intent: Intent?) {
        MyNotificationManager.submitSendBean(NotificationSendBean(context, POPUP_WHERE_PACKAGE))
    }
}
