Simple Background Service

737 views
Skip to first unread message

Durga Prasad

unread,
Dec 16, 2015, 11:15:52 AM12/16/15
to DroidScript
Is it possible to create a background service which will check periodically or always, a notepad file uploaded in webserver, and display the contents in app notification. I have checked the music service, but I am not sure how to relate with this situation.

Any help appreciated.

Steve Garman

unread,
Dec 16, 2015, 2:54:55 PM12/16/15
to DroidScript
If I was trying to do that, I would write a simple DroidScript app with no layouts that uses setInterval to do the job.

Once I had that working, I would convert it to a service afterwards, where the original code becomes Service.js and a front-end app for starting and stopping based on MusicService.js

If you get stuck along the way, feel free to post your code and I am sure lots of help will be available

Durga Prasad

unread,
Dec 27, 2015, 3:01:03 AM12/27/15
to DroidScript
Hi Steve,

I was trying with some samples of creating background services. I tried initially with set interval to show pop-up every 1 second. And it got worked. But the same when I applied service started, then I got error like "unfortunately Droidscript stopped".

In service I just tried to show the popup without set interval.

Here is my service.js file code

//Start/connect to our service.
svc = app.CreateService( "this","this", OnServiceReady );
//svc.SetOnMessage( OnServiceMessage );

//Called after our service has started.
function OnServiceReady()
{
//console.log( "Service Ready" );
app.ShowPopup("service ready");
}


How to use the services properly in app?

Steve Garman

unread,
Dec 27, 2015, 4:07:53 AM12/27/15
to DroidScript
This was my attempt at doing what you described
http://wiki.droidscript.me.uk/doku.php?id=sample_code:file_service
Message has been deleted
Message has been deleted

Steve Garman

unread,
Dec 27, 2015, 7:19:42 AM12/27/15
to DroidScript
I think this spk contains the same code as the wiki sample.
httpService.spk

Durga Prasad

unread,
Dec 27, 2015, 7:21:29 AM12/27/15
to DroidScript
Thanks Steve! Wiki code is worked for my need. But in the notifications part, I am unable to make few things like below.

1) app.vibrate (it doesn't recognize any vibration code while notification)

2) setting large image works, but still small image contains Droidscript logo

Durga Prasad

unread,
Dec 27, 2015, 7:25:18 AM12/27/15
to DroidScript
I just make it worked app vibrate.

Steve Garman

unread,
Dec 27, 2015, 7:31:32 AM12/27/15
to DroidScript
Are you testing an APK?

The notifications sample that comes with DroidScript contains the following comment

//Called when user presses notify with image button.
//Note: The small icon cannot be changed when running with
//the DroidScript IDE, but it will pickup your app icon when
//if you build an APK.

Durga Prasad

unread,
Dec 27, 2015, 8:03:34 AM12/27/15
to DroidScript
Yes after clearing my cache memory and rebuilding the apk finally it worked now!

ansari_abdullah

unread,
May 25, 2017, 8:50:58 PM5/25/17
to DroidScript
will run in background if i closed that app from recent application?
Reply all
Reply to author
Forward
0 new messages