This commit is contained in:
2025-12-28 10:54:06 +01:00
commit de82e50bd5
48 changed files with 2511 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package com.omixlab.mosis
import android.app.Notification
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.core.app.NotificationCompat
class NativeService : Service() {
companion object {
const val NOTIFICATION_ID = 1
const val CHANNEL_ID = "MosisServiceChannel"
init {
System.loadLibrary("mosis-service")
}
}
private external fun getBinderNative(): IBinder
override fun onBind(intent: Intent): IBinder {
return getBinderNative()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
createNotificationChannel()
// Create the notification required for the foreground service
val notification: Notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Mosis Service")
.setContentText("Service is running in the background")
.setSmallIcon(android.R.drawable.ic_dialog_info) // Replace with your app's icon
.setPriority(NotificationCompat.PRIORITY_LOW)
.build()
// Promotes the service to a foreground service
startForeground(NOTIFICATION_ID, notification)
// START_STICKY ensures the service restarts if the system kills it
return START_STICKY
}
private fun createNotificationChannel() {
val serviceChannel = NotificationChannel(
CHANNEL_ID,
"Mosis Service Channel",
NotificationManager.IMPORTANCE_LOW
)
val manager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(serviceChannel)
}
}