diff --git a/taskerpluginlibrary/src/main/java/com/joaomgcd/taskerpluginlibrary/action/ActionReceivers.kt b/taskerpluginlibrary/src/main/java/com/joaomgcd/taskerpluginlibrary/action/ActionReceivers.kt
index 5668e99..27b6d82 100644
--- a/taskerpluginlibrary/src/main/java/com/joaomgcd/taskerpluginlibrary/action/ActionReceivers.kt
+++ b/taskerpluginlibrary/src/main/java/com/joaomgcd/taskerpluginlibrary/action/ActionReceivers.kt
@@ -3,8 +3,11 @@ package com.joaomgcd.taskerpluginlibrary.action
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
+import com.joaomgcd.taskerpluginlibrary.R
import com.joaomgcd.taskerpluginlibrary.extensions.runFromTasker
+import com.joaomgcd.taskerpluginlibrary.runner.ArgsSignalFinish
import com.joaomgcd.taskerpluginlibrary.runner.IntentServiceParallel
+import com.joaomgcd.taskerpluginlibrary.runner.TaskerPluginResultError
import net.dinglisch.android.tasker.TaskerPlugin
@@ -20,11 +23,31 @@ class BroadcastReceiverAction : BroadcastReceiver() {
}
class IntentServiceAction : IntentServiceParallel("IntentServiceTaskerAction") {
+ private var taskerIntent: Intent? = null
+
override fun onHandleIntent(intent: Intent) {
startForegroundIfNeeded()
+ taskerIntent = intent
val result = TaskerPluginRunnerAction.runFromIntent(this, intent)
if (!result.hasStartedForeground) {
startForegroundIfNeeded()
}
}
+
+ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
+ if (intent?.action.equals(ACTION_STOP)) {
+ stopSelf()
+ taskerIntent?.let {
+ TaskerPluginResultError(
+ InterruptedException(getString(R.string.cancelled))
+ ).signalFinish(ArgsSignalFinish(this, it))
+ }
+ return START_NOT_STICKY
+ }
+ return super.onStartCommand(intent, flags, startId)
+ }
+
+ companion object {
+ const val ACTION_STOP = "ACTION_STOP"
+ }
}
\ No newline at end of file
diff --git a/taskerpluginlibrary/src/main/res/values/strings.xml b/taskerpluginlibrary/src/main/res/values/strings.xml
index 4a295fa..113c81d 100644
--- a/taskerpluginlibrary/src/main/res/values/strings.xml
+++ b/taskerpluginlibrary/src/main/res/values/strings.xml
@@ -7,4 +7,5 @@
If there\'s an error, contains an error code
Error Message
If there\'s an error, contains an error message
+ Cancelled