Main app:
function OnStart()
{
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
btn = app.CreateButton( "Stop Service", 0.6, 0.1 );
lay.AddChild( btn );
btn.SetOnTouch( function(){
svc.Stop()
lst.AddItem( "Service Stopped" );
});
app.AddLayout( lay );
lst = app.CreateList( "", 0.8, 0.4 );
lay.AddChild( lst );
svc = app.CreateService( "this","this", OnServiceReady );
svc.SetOnMessage( OnServiceMessage );
}
function OnServiceReady()
{
lst.AddItem( "Service Ready" );
}
function OnServiceMessage( msg )
{
lst.AddItem( msg );
}
Service.js
app.LoadPlugin("MQTT");
var packageName = "com.google.android.apps.maps";
var className = null;
var action = "android.intent.action.VIEW";
function OnStart()
{
app.SendMessage( "Service Started!" );
client.on('connect', OnConnect);
client.on('message', OnMessage);
}
function OnConnect()
{
app.SendMessage("MQTT Connected");
client.subscribe({'test': {qos: 2}}, OnSubScribe);
}
function OnSubScribe()
{
app.SendMessage("MQTT Subscribed");
}
function OnMessage(topic, message)
{
var uri = "google.navigation:q=" + message // + lat + "," + lon;
if(app.IsAppInstalled(packageName))
app.SendIntent(packageName, className, action, null, uri);
else
app.ShowPopup("maps app not installed");