package com.zxdemo.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.util.Log
import com.swiftcleaner.chovey.model.bean.Global.NOTIFICATION_WHERE_INSTALL
import com.zxdemo.notity.NotificationUtils
import com.zxdemo.utils.SpUtils
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit

class AppInstallReceiver : BroadcastReceiver() {

    companion object {
        fun registerReceiver(context: Context) {
            val intentFilter = IntentFilter()
            intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED)//卸载
            intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED)//安装
            intentFilter.addDataScheme("package")
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                context.registerReceiver(
                    AppInstallReceiver(),
                    intentFilter,
                    Context.RECEIVER_EXPORTED
                )
            } else {
                context.registerReceiver(AppInstallReceiver(), intentFilter)
            }
        }
    }

    override fun onReceive(context: Context, intent: Intent) {
        NotificationUtils.sendNotification(context, NOTIFICATION_WHERE_INSTALL)
    }
}
