I want to create a tizen wearable application where I can invoke the native service from tizen web application on button click. I have been finding this for the past week, but could not get round this issue. Can anyone help me with the code? Thanks
Asked
Active
Viewed 512 times
-2
-
1Have you tried message port communication? – Iqbal hossain Aug 23 '17 at 15:57
-
Did you try it ? – Iqbal hossain Aug 27 '17 at 16:53
-
A lot of resources are available which can solve the problem. – Itban Saeed Sep 11 '19 at 09:11
2 Answers
1
It is possible. I found this from here Receiving Bundle from Native App.
Service Code
#include <tizen.h>
#include <service_app.h>
#include <bundle.h>
#include <message_port.h>
#include "messageportnativeservicesend.h"
#define TAG "xyz"
void
sendMessage(char *remote_app_id,char *remote_port,bundle *reply){
int ret = message_port_send_message(remote_app_id, remote_port, reply);
if (ret != MESSAGE_PORT_ERROR_NONE)
dlog_print(DLOG_ERROR, TAG, "message_port_check_remote_port error: %d", ret);
else
dlog_print(DLOG_INFO, TAG, "Send message done");
dlog_print(DLOG_INFO, TAG, "Send message was called");
}
void
test_check_remote_port(char *remote_app_id,char *remote_port,bool result)
{
int ret;
ret = message_port_check_remote_port(remote_app_id,remote_port,&result);
if (ret != MESSAGE_PORT_ERROR_NONE)
dlog_print(DLOG_ERROR, TAG, "message_port_check_remote_port error: %d", ret);
}
void msgPort()
{
char *remote_app_id="mRLmiKfKmV.MessagePortWebReceiver";
char *remote_port="CrossPort";
bool result;
test_check_remote_port(remote_app_id,remote_port,result);
dlog_print(DLOG_DEBUG, TAG ,"Remote port exists: %s", result ? "true" : "false");
bundle *reply;
reply=bundle_create();
char *array[] = {"XY","YZ","ZX","AB"};
bundle_add_str(reply,"test","A");
bundle_add_str_array(reply,"service",array, 4);
dlog_print(DLOG_DEBUG, TAG, "Bundled Successfully");
if (result){
sendMessage(remote_app_id,remote_port,reply);
bundle_free(reply);
}
}
bool service_app_create(void *data)
{
msgPort();
return true;
}
void service_app_terminate(void *data)
{
// Todo: add your code here.
return;
}
void service_app_control(app_control_h app_control, void *data)
{
// Todo: add your code here.
return;
}
static void
service_app_lang_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LANGUAGE_CHANGED*/
return;
}
static void
service_app_region_changed(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_REGION_FORMAT_CHANGED*/
}
static void
service_app_low_battery(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_BATTERY*/
}
static void
service_app_low_memory(app_event_info_h event_info, void *user_data)
{
/*APP_EVENT_LOW_MEMORY*/
}
int main(int argc, char* argv[])
{
char ad[50] = {0,};
service_app_lifecycle_callback_s event_callback;
app_event_handler_h handlers[5] = {NULL, };
event_callback.create = service_app_create;
event_callback.terminate = service_app_terminate;
event_callback.app_control = service_app_control;
service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
return service_app_main(argc, argv, &event_callback, ad);
}
Web Code:
window.onload = function () {
// TODO:: Do your initialization job
// add eventListener for tizenhwkey
document.addEventListener('tizenhwkey', function(e) {
if(e.keyName === "back") {
try {
tizen.application.getCurrentApplication().exit();
} catch (ignore) {
}
}
});
/* MessagePortCallback instance */
function onReceived(data, remoteMsgPort) {
console.log("Local port Listener Called");
for (var i = 0; i < data.length; i++){
var keyX = data[i].key;
console.log("key:" + keyX);
for (var j = 0; j < data[i].value.length; j++){
var valueX = data[i].value[j];
console.log("value:" + valueX);
}
}
}
function messagePort(){
var localPort = tizen.messageport.requestLocalMessagePort("CrossPort");
localPort.addMessagePortListener(onReceived);
console.log("Local port Listener Registered");
}
// Sample code
var textbox = document.querySelector('.contents');
textbox.addEventListener("click", function(){
messagePort();
var box = document.querySelector('#textbox');
box.innerHTML = (box.innerHTML === "Basic") ? "Sample" : "Basic";
});
};
Demo:

Iqbal hossain
- 1,778
- 3
- 17
- 24
0
I believe you are looking to develop a "Hybrid" tizen application. As per tizen.org
"The Tizen platform allows you to create hybrid application packages, which combine a Web UI application and 1 or more native service or widget applications."
There is also a sample application to do this. Hybrid Sample App
Here is more information on how to package it. Tizen Hybrid Applications

Sanjeev BA
- 307
- 1
- 6