언어 설정

Menu
Sites
Language
Native Service App

Hi,

I have my webapp in Tizen and to accomplish a task I need to use Native Service, i.e. Hybrid App. The task is that I need to call an API (which fetches some data from internet) periodically and it has to run in background even if app closes, hence I have to use services. I am using alarm for that. Once the alarm expires, the service has to call that API and get the data then send to webapp where I can display it as notification. 

I am totally new to Native Service app and have no idea how to complete this task. Please tell me about how to go step by step for this task.

Thanks

Responses

15 댓글
Alex Ashirov

Hi,

It’s quite clear described in the Tizen help:

https://developer.tizen.org/documentation/articles/hybridwebapp-sample-overview

https://developer.tizen.org/documentation/articles/hybridserviceapp-sample-overview?langswitch=en

 

The links above describe hybrid web and native service samples delivered with the Tizen SDK.

Alex Dem

Hi, and fyi ,in additional :
1) service app tutorial:
https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.native.appprogramming/html/tutorials/app_tutorial/service_app_tutorial.htm
2) message port tutorials (for interaction between web and native app):
https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.native.appprogramming/html/tutorials/app_tutorial/message_port_tutorial.htm
https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.web.appprogramming/html/guide/io_guide/messageport.htm
Alexey.

Dheeraj Khoriya

Thanks a lot Alex.

These tutorials are helpful and I am able to do the service to webapp communication successfully. 

Though I have other problem now: now that the service is alltime running and I am able to receive message from service to my webapp, I want to trigger the service at given time interval periodically (trigger here implies that service which is running in the background needs to do the specific job at times requested by webapp). In my case: I want the service to fetch data from internet (I am able to do that using CURL) and send it to webapp. Can you help in this too ? I know about alarm api but how do I use that in this case ?

Alex Dem

Hi,
If you mean how to perform inside Native service request periodically you could try use Ecore Timer :
https://developer.tizen.org/dev-guide/2.3.0/org.tizen.mobile.native.apireference/group__Ecore__Timer__Group.html

Inside Web app you could try to use window.setInterval and send appropriate command to Native service via message port.

Do you mean this?
Alexey.

Dheeraj Khoriya

Hi Alex,

Since I am getting the period input from user in webapp, I need the service to cater that request after that particular duration of time periodically. Now 

1) How do I call the service periodically from webapp? (I am able to launch service for the first time and getting the data to webapp from native but the service does not get triggered the second time because it is already running and alarm api in webapp won't help if the service is already running). I could use ecore_timer but how do I notify the webapp when the app is closed?

2) It would be great if I am able to close the service just after using it. In this case, the alarm API in webapp would work since the service is already closed and would relaunch it and I can get notified which is what I want. But I am unable to send data to service app for the termination of service after using. By default, when the service is launched, these functions get called automatically.

bool service_app_create()
void service_app_control()

But not this

void service_app_terminate()

How do I make a call from webapp to terminate the service so that my purpose if fulfilled?

 

Thanks

colin Rao

1. Use app control api to launch and terminate the service

2. configure your service to not auto-restart, and not start on-boot in manifist as below.

<service-application component-type="svcapp" auto-restart="false" on-boot="false"
Dheeraj Khoriya

Hi Colin,

Thanks for the info. But the app control api to kill the service application requires Partner Level Signing which I don't have.

Alex Dem

Hi,
As I know there is no api which could kill another app with known AppId from web app. You could manage how to terminate your service app this way:
1. send command from web app via message port.
2. terminate service app using service_app_exit().

But i don't see necessity. Per my opinion your service could be always launched with 'auto-restart'=true and 'on boot'=true in manifest. In this case you will not need launch native service every time (using application/alarm api) and perform some actions. We could send command via message port which will shoould initiate your http request.
Alexey.

Dheeraj Khoriya

Hey,

What you are saying is absolutely correct. But I was actually trying to be free from the task of sending message from webapp to service app and was wondering whether there is other way around. I am already confused as to how the message ports are working. 

For the part of necessity of closing the application, consider the situation, webapp is closed (user is not using it), service app is running in background and I need to remind the service to fetch data from interne tafter every certain period of interval. How do I do that with the webapp closed ? 

Let me know if I accomplish this without using message ports and without any communication between service app and webapp.

 

Thanks

Alex Ashirov

Hi,

In this case the only way is to create time on the service app side.

Alex Dem

If the the web app closed I could propose:
1. Use timer inside always running native service.
2. Maybe launch native service via alarm from web app and after perform http request terninate service app with service_app_exit()  (alarm should start native service app due schedule if web app have been closed even, but untill web app is not uninstalled).
Alexey. 

Dheeraj Khoriya

Hi,

In first case, I have to send "time-period" (user input) from webapp to service app in order to add timer in service app accordingly (Hence communication is required).

In 2nd case, I implemented service_app_exit() in service after I have done my job (fetched data and sent to webapp), service gets terminated by this but then this service does not get start again (in both the cases, when webapp is ON and when webapp is CLOSED).

I am using this as alarm api in webapp to trigger service

var alarm = new window.tizen.AlarmRelative(0.3 * window.tizen.alarm.PERIOD_MINUTE);
        window.tizen.alarm.add(alarm, gServiceAppId);
    	startMessagePort();

so it should trigger service after every (0.3*60 = 18 seconds) but it is not at all triggering, ever. gServiceAppId is the service app id after which I register the local port for receiving messages from service app. 

Can you help in this ? I appreciate your persistent help in my issues. 

Thanks,

Dheeraj

Alex Dem

Hi,
It should work . I have checked on emulator. Please look at alarm api:
First param is delay before first launch. Second (optional) is period.
AlarmRelative(long delay, optional long? period);
I suppose you should configure alarm with both params this way:
var alarm = new tizen.AlarmRelative(0.3 * tizen.alarm.PERIOD_MINUTE, 0.3 *tizen.alarm.PERIOD_MINUTE);
Alexey.

Dheeraj Khoriya

Hi Alex,

It is working perfectly fine. Thanks a lot, really.

Actually initially I had done the same thing but somewhere in the middle for testing purposes, I changed to only 1 parameter and then forgot. You have been a great help all along. For now, application's functionality wise I am able to do everything successfully, for rest I'll keep bugging here on the Tizen forum. Thank You very much.

 

Dheeraj

 

Shraddha Shravagi

Hello,

Even I am trying to do same. Could you please help me with it?

Can u share a sample project for web and native service which communicate via messagePort?

I am getting error at requestRemoteMessagePort as null pointer exception.

 

Regards,

Shraddha