Intent from service

105 views
Skip to first unread message

Daniele

unread,
Sep 19, 2022, 5:27:11 PM9/19/22
to DroidScript
Hi everyone,
i need to run a "SendIntent" command when droidscript is in the background.
Currently by using a service, the "SendIntent" command works when the main app is in the background but droidscript must be in the foreground.
If I use "ShowPopup" instead of "SendIntent", with  droidscript in the background I can see the popups appair.

Any suggestions?

Thanks

Right2TheV0id

unread,
Sep 20, 2022, 6:02:01 AM9/20/22
to DroidScript
Can you provide minimal code to reproduce your problem?

Mohamed Ibrahim (Mounir)

unread,
Sep 20, 2022, 11:37:03 AM9/20/22
to DroidScript
4186 my cod 

Daniele

unread,
Sep 20, 2022, 6:41:20 PM9/20/22
to DroidScript
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 = mqtt.connect('ws://broker.emqx.io:8083/mqtt')
    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");

Right2TheV0id

unread,
Sep 21, 2022, 9:17:08 AM9/21/22
to DroidScript
Here is what I did and the results I have:
1. Started your program
2. Pressed the home button of the device (everything is now in "background")
3. google maps opened and displayed "Welcome to Google Maps Navigation"
Isn't it the result you're looking for?

Dave

unread,
Sep 21, 2022, 9:46:09 AM9/21/22
to DroidScript
Unfortunately in Android 10 and above you can't launch activities from the background anymore - 


You can show a notification though, which when touched by the user will show an activity.

Reply all
Reply to author
Forward
0 new messages