SEPIA-Framework / sepia-docs

Documentation and Wiki for SEPIA. Please post your questions and bug-reports here in the issues section! Thank you :-)
https://sepia-framework.github.io/
236 stars 16 forks source link

Call Android Intent from Smart Service #121

Closed schroedingersZombie closed 2 years ago

schroedingersZombie commented 2 years ago

Hi,

I've created a smart service and would like it to call an Android intent via the client app on my smartphone. I've found the sendRemoteAction in the ServiceBuilder, but the client code does not seem to have a handler for calling intents sent via this method. Am I missing something or is there currently no way to do this?

I think I would be able to implement this in the client code, if it is not possible yet, and create a PR. Would the file www/scripts/sepiaFW.webSocket.js in the client app in the lines following 2154 be the correct point to start this?

fquirin commented 2 years ago

Hi,

happy to hear you are building a custom service :-).

There are two options implemented into the client to call Android intents:

The corresponding service actions are:

The PLATFORM_CONTROLS command is using them, maybe it helps to check it out:

There is some more info in the SEPIA Teach-UI examples that might help.

Basically "clientControlFun" can trigger everything that is available via SepiaFW.client.controls.handle which is (v0.24.0):

var availableControls = {
     "settings": Controls.settings,
    "alwaysOn": Controls.alwaysOn,
    "volume": Controls.volume,
    "media": Controls.media,
    "searchForMusic": Controls.searchForMusic,
    "clexi": Controls.clexi,
    "platformFunction": Controls.platformFunction,
    "meshNode": Controls.meshNode,
    "runtimeCommands": Controls.runtimeCommands
}

platformFunction is the one to look out for. Via "controlData" you can pass "android" as platform and request type "androidActivity" or "androidBroadcast" which will call SepiaFW.android.intentActivity(req.data) or SepiaFW.android.intentBroadcast(req.data).

There might be some limitations to the SepiaFW.android.intent... functions. What would you like to call?

In your service you can use the platform feature if you want to make sure the client can actually handle Android intents:

//Check platform
Platform platform = CLIENTS.getPlatform(nluResult.input.clientInfo);
if (platform.equals(Platform.browser)){
    ...
}else if (platform.equals(Platform.android)){
    ...
}else{
    ...
}
*/

Hope that helps :slightly_smiling_face:

schroedingersZombie commented 2 years ago

Thank you! I think that helps. I got diverted by the remoteAction :D But I think I now know the way forward.