Languages

Menu
Sites
Language
Communication between Native service or app and widget

I am new to Tizen. I need to know about communication process of Native Service/App with Web Widget. Any one has any idea or code example ?

please share 

Responses

3 Replies
Shaswati Saha

I've used Appcontrol functionality in this purpose. You may follow the steps below:

1. Take one Web widget app & one Native service app.

2. Modify the main.js file of the widget app as below:
 

    var mainPage = document.getElementById("content-text"); 
	mainPage.onclick=click;
	mainPage.addEventListener('click', click);
	function click() {
		var obj = new tizen.ApplicationControlData("YOUR_WIDGET_APP_ID", ["Success"]); //you'll find the app id in config.xml file.
		var obj1 = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/service",
				null,
				null,
				null,
				[obj] 
		);
		//you'll find the service app id from the manifest file of service app.
		tizen.application.launchAppControl(obj1,
				"YOUR_SERVICE_APP_ID",
				function() {console.log("Launch Service succeeded"); },
				function(e) {console.log("Launch Service failed : " + e.message);}, null);

	}

3. In the service_app_control() function of the service app write the below code snippet.
 

char *operation;
	char *app_id;
	app_control_get_operation(app_control, &operation);

	if (!strcmp(operation, "http://tizen.org/appcontrol/operation/service")) {
		char *message;
		app_control_get_extra_data(app_control, "YOUR_WIDGET_APP_ID", &message);
		dlog_print(DLOG_DEBUG, "shaswati", " %s ", message);

	}

4. Install both of the applications. Now, you'll get to see a message whenever you click on the widget app text "Hello Widget". 

Hope it'll help.

manish d

question was how to communicate with service.... that means exchannging data between service and widget. 

Shaswati Saha

You may use appControlReplyCallback in that case. Use the below code snippets.

In widget app (main.js):

var mainPage = document.getElementById("content-text"); 
    mainPage.onclick=click;
    mainPage.addEventListener('click', click);
	function click() {
		
		var appControlReplyCallback = {
				// callee sent a reply
				onsuccess: function(data) {

					document.getElementById("content-text").textContent = data[0].value[0];

				},
				// callee returned failure
				onfailure: function() {
					console.log('The launch application control failed');
				}
		}
		//document.getElementById("content-text").textContent = "My String";
		var obj = new tizen.ApplicationControlData("YOUR_WIDGET_APP_ID", ["Success"]);
		var obj1 = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/service",
				null,
				null,
				null,
				[obj] 
		);
		
		tizen.application.launchAppControl(obj1,
				"YOUR_SERVICE_APP_ID",
				function() {console.log("Launch Service succeeded"); },
				function(e) {console.log("Launch Service failed : " + e.message);}, appControlReplyCallback);

	}

 

In service app (service_app_control() function):

char *operation;
	app_control_get_operation(app_control, &operation);

	if (!strcmp(operation, "http://tizen.org/appcontrol/operation/service")) {
		char *message;
		app_control_get_extra_data(app_control, "YOUR_WIDGET_APP_ID", &message);
		dlog_print(DLOG_DEBUG, "shaswati", " %s ", message);
		app_control_h reply;
		app_control_create(&reply);
		app_control_add_extra_data(reply, APP_CONTROL_DATA_SELECTED, "Ok");
		app_control_reply_to_launch_request(reply, app_control, APP_CONTROL_RESULT_SUCCEEDED);
		app_control_destroy(reply);

	}