Skip to main content

Code Details with Examples

1. Gleo Action

1.1 Android Intent Conversion

  • When Gleo AI interprets the user’s request, “Please add a meeting reminder at 3 PM today,” it creates the following JSON object:
{
"packageName": "ai.dot42.pleos.reminderapp",
"action": "ADD_REMINDER",
"actionParameters": {
"title": "Meeting",
"dateTime": "2025-02-20T06:00:00Z"
}
}
  • Then, Gleo AI converts the object into an Android Intent, which is then sent to the external app. The conversion follows rules below:

    • The value of action is set as the Intent action.
    • The value of packageName is used to specify the target app.
    • The actionParameters JSON object is parsed, and each key-value pair is individually added to the Intent (putExtra).
  • Below is an example of sending data to and launching an external app via sendBroadcast (component="activity"):

Sending Side (Gleo AI)
val intent = Intent()
intent.action = "ADD_REMINDER"
intent.putExtra(
"ACTION_PARAM",
"\"{\"title\":\"Meeting\", \"dateTime\":\"2025-02-20T06:00:00Z\"}\""
)
intent.setPackage("ai.dot42.pleos.reminderapp")
context.startActivity(intent)
Receiving Side (3rd-party App)
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// ...
val bundle = intent?.extras
bundle?.let { data ->
runCatching {
val actionParam = data.getString("ACTION_PARAM")
// ...
}.onFailure {
Log.e(logTag, "Failed to get intent extras: $it")
}
}
}
}
  • Below is an example of sending data to and launching an external app via startActivity (component="service"):
Sending Side (Gleo AI)
val intent = Intent()
intent.action = "ADD_REMINDER"
intent.putExtra(
"ACTION_PARAM",
"\"{\"title\":\"Meeting\", \"dateTime\":\"2025-02-20T06:00:00Z\"}\""
)
intent.package = "ai.dot42.pleos.reminderapp"
context.sendBroadcast(intent)
Receiving Side (3rd-party App)
class CustomReceiver : BroadcastReceiver() {
override fun onReceive(
context: Context,
intent: Intent
) {
if (intent.action == "ADD_REMINDER") {
val rawJson = intent.getStringExtra("ACTION_PARAM") ?: "{}"
try {
// JSON parsing
val json = JSONObject(rawJson)
val actionParams = json.optJSONObject("actionParameters") ?: JSONObject()
val title = actionParams.optString("title", "No Title")
val dateTime = actionParams.optString("dateTime", "No DateTime")

// To Do..
Log.d("ReminderReceiver", "Title: $title, DateTime: $dateTime")
} catch (e: Exception) {
e.printStackTrace()
Log.e("ReminderReceiver", "Failed to parse actionParameters")
}
}
}
}

2. Callback

  • Gleo AI must receive a Broadcast in the following format:
{
"functionName": "SWITCH_BAND",
"status": "success",
"message": "Successfully switched to the requested radio channel.",
"data": "[{\"frequency\": \"91.9MHz\", \"frequencyBand\": \"FM\", \"stationName\": \"MBC\", \"channelName\": \"MBC FM4U\"}]"
}
  • Since Gleo AI is an Android Service, it can receive broadcasts.
  • Below is an example implementation of sending a Broadcast Response to Gleo AI:
Sending Side (3rd-party App)
import android.content.Intent
import android.util.Log
import org.json.JSONArray
import org.json.JSONObject

fun sendGleoBroadcast(functionName: String, status: String, message: String, packageName: String) {
runCatching {
val dataObject = JSONObject().apply {
put("key", "value") // Add required data
}
val dataArray = JSONArray().apply {
put(dataObject)
}
val jsonObject = JSONObject().apply {
put("functionName", functionName)
put("status", status)
put("message", message)
put("data", dataArray)
}

Intent("ai.pleos.playground.intent.action.APP_ACTION_RESPONSE").apply {
putExtra("result", status)
putExtra("packageName", packageName)
putExtra("response", jsonObject.toString())
}.also {
sendBroadcast(it)
Log.d("ThirdPartyApp", "respondAction success jsonObject: $jsonObject")
}
}.onFailure {
Log.e("ThirdPartyApp", "respondAction onFailure >> $it")
}
}
Sending Side (3rd-party App)
sendGleoBroadcast("SWITCH_BAND", "success", "Successfully switched to the requested radio channel.", "[{\"frequency\": \"91.9MHz\", \"frequencyBand\": \"FM\", \"stationName\": \"MBC\", \"channelName\": \"MBC FM4U\"}]")