//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a text control to show data log.
txt = app.CreateText( "", 0.9, 0.8, "Multiline,Left" );
txt.SetTextColor( "#ffffffff" );
lay.AddChild( txt );
//Create a 'Set Alarm' button.
btnSet = app.CreateButton( "Set Alarm", 0.4, 0.1 );
btnSet.SetMargins( 0, 0.05, 0, 0 );
btnSet.SetOnTouch( btnSet_OnTouch );
lay.AddChild( btnSet );
//Create and start location sensor.
//(Achievable update rate is hardware specific)
loc = app.CreateLocator( "GPS,Network" );
loc.SetOnChange( loc_OnChange );
loc.SetRate( 10 ); //10 seconds.
loc.Start();
//Add main layout to app.
app.AddLayout( lay );
//Create array to hold log messages.
log = new Array();
Log( "Locating..." );
//Add layout to app.
app.AddLayout( lay );
//Create media player and load file.
player = app.CreateMediaPlayer();
player.SetFile( "/Sys/Snd/Poing.ogg" );
}
//Called when user touches our 'Set Alarm' button.
function btnSet_OnTouch()
{
//Get current time in milliseconds.
var now = new Date().getTime();
//Set alarm for 3 seconds time.
app.SetAlarm( "Set", 1234, OnAlarm, now + 120000);
app.ToBack();
}
//Called when alarm is triggered.
//(Even if your app is closed)
function OnAlarm( id )
{
app.ShowPopup( "Got Alarm: id = " + id );
player.SeekTo( 0 );
player.Play();
}
//Called when we get a change in location.
function loc_OnChange( data )
{
//btnSet_OnTouch();
Log( data.provider+": Lat "+data.latitude+", Lng "+data.longitude
+", Spd "+data.speed+", Bear "+data.bearing
+", Alt "+data.altitude+", Accu "+data.accuracy+"" );
}
//Add messages to log.
function Log( msg )
{
if( txt.GetLineTop( txt.GetLineCount() ) >= 0.8 )
log.shift();
log.push( msg + "\n" );
txt.SetText( log.join("") );
}I must admit I was under a misunderstanding about the services problem.
I thought that while we were targetting api 26 we were safe from that but apparently that is the cutoff point.
This may well not help but does your Service.js contain a SetAlarm?
If not, I would recommend try adding this code in the service OnStart function
var now = new Date().getTime();
app.SetAlarm( "Repeat", 1324, null, now + 3000, 3000 );
I would be interested to hear if it helps.
The only other "fix" I can suggest, if you don't need to post your app on Google Play is a build.json file with a targeSdkVersion lower than 26.
To be honest, that hasn't been tested much with the most recent version of DroidScript either.
I'm hoping foreground services may be available in the next alpha. It may be that will help your problems.