setup alert receiver

This commit is contained in:
moon 2026-07-22 00:11:45 +06:30
parent 706a48d1d1
commit f1a2707190
4 changed files with 109 additions and 2 deletions

View File

@ -38,6 +38,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MOBPOS">
<receiver android:name=".auto_settlement.AlarmReceiver" android:exported="false"/>
<service android:name=".auto_settlement.AutoSettleService" android:exported="false" android:foregroundServiceType="dataSync"/>
<activity
android:name="com.mob.utsmyanmar.MainActivity"
android:exported="true"

View File

@ -1,10 +1,11 @@
package com.mob.utsmyanmar
import android.os.Build
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.annotation.RequiresApi
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
@ -15,12 +16,16 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
@RequiresApi(Build.VERSION_CODES.N)
override fun onCreate(savedInstanceState: Bundle?) {
if (intent.getBooleanExtra("AUTO_SETTLEMENT", false)) {
print("auto Settlement will run here")
}
// installSplashScreen()
super.onCreate(savedInstanceState)
enableEdgeToEdge()
hideSystemBars()
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
// window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
setContent {
MOBPOSTheme {
val navController = rememberNavController()

View File

@ -0,0 +1,21 @@
package com.mob.utsmyanmar.auto_settlement
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.content.ContextCompat
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class AlarmReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val serviceIntent = Intent(context, AutoSettleService::class.java)
if (context != null) {
ContextCompat.startForegroundService(
context,
serviceIntent
)
}
}
}

View File

@ -0,0 +1,79 @@
package com.mob.utsmyanmar.auto_settlement
import android.annotation.SuppressLint
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Intent
import android.os.Build
import android.os.IBinder
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import com.mob.utsmyanmar.MainActivity
import com.mob.utsmyanmar.R
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation
import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class AutoSettleService : Service(){
companion object {
const val CHANNEL_ID = "auto_settlement_channel"
const val NOTIFICATION_ID = 1002
}
override fun onCreate() {
super.onCreate()
startForegroundNotification()
}
@RequiresApi(Build.VERSION_CODES.N)
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if(!SystemParamsOperation.getInstance().settlementStatus){
stopSelf()
return START_NOT_STICKY
}
launchSettlement()
stopForeground(STOP_FOREGROUND_REMOVE)
stopSelf()
return START_NOT_STICKY
}
override fun onBind(intent: Intent?): IBinder? = null
@SuppressLint("ForegroundServiceType")
private fun startForegroundNotification(){
val manager = ContextCompat.getSystemService(this, NotificationManager::class.java)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
val channel = NotificationChannel(
CHANNEL_ID,
"AUTO SETTLEMENT",
NotificationManager.IMPORTANCE_LOW
)
manager?.createNotificationChannel(channel)
}
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.logo_mob)
.setContentTitle("Auto Settlement")
.setContentText("Processing...")
.build()
startForeground(NOTIFICATION_ID, notification)
}
private fun launchSettlement() {
val intent = Intent(this, MainActivity::class.java).apply {
addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
)
putExtra("AUTO_SETTLEMENT", true)
}
startActivity(intent)
}
}