Search code examples
javascripttizentizen-web-appsamsung-galaxy-gear

Opening URL from watch on phone (Tizen)


I am developing a Tizen Web App for the Samsung Gear. (Using Tizen 2.4)

Currently I try to add a function which allows the user to open a link on his phone via the watch. So when he presses a button, an URL will open in the phone's default browser. I noticed other smart watch apps have this functionality.

After browsing these forums, I found a code example:

var appControl = new tizen.ApplicationControl('http://tizen.org/appcontrol/operation/view',
'https://www.tizen.org', null, null, null, null);

tizen.application.launchAppControl(appControl, null, function() {
console.log('launch application control succeed');
}, function(e) {
console.log('launch application control failed. reason: ' + e.message);
}, null);

However, when I try to run it, I get the following error: "launch application control failed. reason: No matched application found."

My app does have the following privlige in it's config file added:

<tizen:privilege name="http://tizen.org/privilege/application.info"/>
<tizen:privilege name="http://tizen.org/privilege/application.launch"/>
  1. Is this this the correct application to use to open a link on the phone's browser?
  2. Are these all the required privileges for this feature?
  3. Why is the application not found?

Solution

  • Found it You will need the application.launch privilege.

    function openBrowserOnPhone(url) {
        var appid = "com.samsung.w-manager-service";
        var type = "phone";
    
        var extra_data = [
                  new tizen.ApplicationControlData("msgId", ["mgr_install_host_app_req"]),
                  new tizen.ApplicationControlData("type", [type]),
                  new tizen.ApplicationControlData("deeplink", [url])];
        var appControl = new tizen.ApplicationControl(
                   "http://tizen.org/appcontrol/operation/default",
                   null,
                   null,
                   null,
                   extra_data);
        var appControlReplyCallback = {
                onsuccess: function(data) {
                    console.log("launchUrl reply success");
                    console.log("success: data = " + JSON.stringify(data));
                },
                onfailure: function() {
                    console.log("launchUrl reply failed");
                }
            };
        try {
            tizen.application.launchAppControl(
                     appControl,
                     appid,
                     function() { console.log("intentBorba", "launchUrl success"); },
                     function(err) { console.log("intentBorba", "launchUrl failed: " + err.message); },
                     appControlReplyCallback);
        } catch(err) {
            console.error("[launcher] " + err);
        }
    }
    

    You can use it anywhere like this:

    openBrowserOnPhone('http://google.com')