Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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"
}
}
1 change: 1 addition & 0 deletions taskerpluginlibrary/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<string name="error_code_description">If there\'s an error, contains an error code</string>
<string name="error_message">Error Message</string>
<string name="error_message_description">If there\'s an error, contains an error message</string>
<string name="cancelled">Cancelled</string>
</resources>