mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-01-31 17:44:46 +01:00
adding some implementation of HeadlessSmsSendService
This commit is contained in:
parent
ce886b5b87
commit
9103968595
@ -2,10 +2,29 @@ package com.simplemobiletools.smsmessenger.services
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import com.klinker.android.send_message.Settings
|
||||
import com.klinker.android.send_message.Transaction
|
||||
import com.simplemobiletools.smsmessenger.extensions.getThreadId
|
||||
|
||||
class HeadlessSmsSendService : Service() {
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return null
|
||||
override fun onBind(intent: Intent?) = null
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
try {
|
||||
if (intent == null) {
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
val number = intent.dataString!!.removePrefix("sms:").removePrefix("smsto:").removePrefix("mms").removePrefix("mmsto:").trim()
|
||||
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
|
||||
val settings = Settings()
|
||||
settings.useSystemSending = true
|
||||
val transaction = Transaction(this, settings)
|
||||
val message = com.klinker.android.send_message.Message(text, number)
|
||||
transaction.sendNewMessage(message, getThreadId(number))
|
||||
} catch (ignored: Exception) {
|
||||
}
|
||||
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user