Search code examples
javascripttizentizen-web-app

Tizen gear web app, launch web app with text data


I have a watch face that launches another app using the code below:

var appId ="aGbGC3smHe.apptwo"; // app to be launched 

tizen.application.launch(appId); 

It works, but I want to send text from the watch face to the second app and have the second app do something with it like below

if (senttext === "hello"){
console.log("hello")
}

I saw this code which I think might be half the answer but I dont know how to deal with the text at the other end....

var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/share",null,"text/*",null ,[new tizen.ApplicationControlData("text", [message])]);

tizen.application.launchAppControl(appControl, null,function()console.log("launch application control succeed");
},function(e) {alert("ERROR")});

can I please know how to do this in Tizen Web? ... Thank you :)


Solution

  • You may try the steps below:

    1. Use the code below in the Watch Application(Watch face app)

    var obj = new tizen.ApplicationControlData("Paste_Your_Watch_Face_APP_ID_Here", ["Hello"]);
    
    var obj1 = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/default",
    				null,
    				null,
    				null,
    				[obj] );
            
    tizen.application.launchAppControl(obj1,
    				"aGbGC3smHe.apptwo",
    				function() {console.log("Launch Service succeeded"); },
    				function(e) {console.log("Launch Service failed : " + e.message);},
    				null);

    1. Use the code below in the second app. Now, if you click on the word "Basic" it'll show the data sent from the Watch App.

        var mainPage = document.querySelector('#main');
    
        mainPage.addEventListener("click", function() {
            var contentText = document.querySelector('#content-text');
    
            var reqAppControl = tizen.application.getCurrentApplication().getRequestedAppControl();
    
            if (reqAppControl) {
            	var reqData = reqAppControl.appControl.data;
            	for (var i = 0; i < reqData.length; i++) {
                    console.log("#" + i + " key:" + reqData[i].key);
                    for (var j = 0; j < reqData[i].value.length; j++) {
                       console.log("   value#" + j + ":"+reqData[i].value[j]);
                       // Process the data
                       contentText.innerHTML = reqData[i].value[j];
                    }
         	 }
                
            }
            
        });

    Hope it'll help!