Android Serder App Enhanced Features
enhanced features sender application can be more powerful with the following advanced feature like wow,ble,multitsking,install etc related info android api guide smartviewsdkcastvideo startargs authentication should only be passed with secure connection" coming soon startarg can be 'login user info','deeplink','authtoken' etc above mobile library android 2 0 18 and ios 2 2 2 mobile app android must write "id" startargs map's key simple string "id","aaa" ; json , "id",data{"id" "xx","pw" "1234","pairing_code" "xx@1234"} //string type map<string,object> startargs1 = new hashmap<string, object> ; object payload = "aaa"; startargs1 put message property_message_id,payload ; mapplication = mservice createapplication mapplicationid, mchannelid,startargs1 ; //json object type jsonobject test2 = new jsonobject ; try { test2 put "userid","xx" ; test2 put "userpw","1234" ; test2 put "paircode","xx@1234" ; } catch jsonexception e { e printtacktrace ; } map<string,object> startargs2 = new hashmap<string, object> ; object payload = test2 tostring ; startargs2 put message property_message_id,payload ; mapplication = mservice createapplication mapplicationid, mchannelid,startargs2 ; tv web app to received "start args", must write "payload" to get data msf local function err, service { var reqappcontrol = tizen application getcurrentapplication getrequestedappcontrol ; log "reqappcontrol =" + reqappcontrol + ", appcontrol = "+reqappcontrol appcontrol ; if reqappcontrol && reqappcontrol appcontrol { var data = reqappcontrol appcontrol data; for var i = 0; i < data length; i++ { log "wrt param #" + i + " key " + data[i] key ; for var j = 0; j < data[i] value length; j++ { console log "wrt param #" + i + " #" + j + " value " + data[i] value[j] ; } if data[i] key == "payload" { log "payload =" + data[i] value[0] ; var payload = data[i] value[0]; } } } install api mobile app can make tv to show of webapp installation page when tv webapp is not exist install api is possible to make this scenario also, you have 2 times chance to call install 1 getinfo you call getinfo then you received onerror code '404' that means your tv webapp not exist 2 connect you call connect then you received onerror code '404' that means your tv webapp not exist 3 code flow //1 create appication mapplication = mservice createapplication mapplicationid, mchannelid ; //2 get appicationinfo if you need mapplication getinfo new result<applicationinfo> { @override public void onsuccess applicationinfo applicationinfo { log d tag, "getinfo " + applicationinfo tostring ; } @override public void onerror com samsung multiscreen error error { if error getcode == 404 { //install the application on the tv //note this will only bring up the installation page on the tv //the user will still have to acknowledge by selecting "install" using the tv remote application install new result<boolean> { @override public void onsuccess boolean result { log d logtag, "application install onsuccess " + result tostring ; } } ; } } ; } ; //3 launch installed app mapplication connect new result<client> { @override public void onsuccess client client { log d tag, "application connect onsuccess " + client tostring ; } @override public void onerror com samsung multiscreen error error { if error getcode == 404 { //install the application on the tv //note this will only bring up the installation page on the tv //the user will still have to acknowledge by selecting "install" using the tv remote application install new result<boolean> { @override public void onsuccess boolean result { log d logtag, "application install onsuccess " + result tostring ; } } ; } } ; } wow wake on wireless lan this section explains how a samsung smart tv can use wake on wireless lan wowlan to power on a previously discovered tv this enables the mobile device to subsequently start and interact with applications on the samsung tizen tv notefor '16 tv, wol wake-on-lan , turning on the tv on connection with lan cable, is also supported latest smartviewsdk include enhaned wow feature sdk 2 4 0 makes your app enable wow function automatically without no source code change if your app have been connected once, sdk manage the tv device list for wow feature sdk handles below basic ui scenario basic ui scenario turn the tv off put to standby appears marked as “tv_name standby ” within 7 seconds select the tv the tv power on the tv webapp or dmp should start loading on the tv the video should start playing on the tv new wow apis smartview sdk now supports wow enabled as default for 2016 and above samsung smarttvs it enables user to connect to a tv currently in standby mode upon making a connect call to a standby tv, it tries to turn on the tv and to establish a connection with the same standby tvs are those tvs to which user has connected successfully to at-least once in the past & are now in standby mode search start this api will start discovery & list standby tvs by default search start false stop discovery from listing standby tvs service remove remove a standby device from the device list until it is not again connected search clearstandbydevicelist remove all standby devices form t the device list errors following error codes have been added, to identify problems w r t wow feature error_connect_failed connect request fails due to some internal error error_host_unreachable host is unreachable this error occurs when wow api is not able to wake the tv up or tv’s ip was changed & tv is no more broadcasting discovery packets error_already_connected when connect is called on already connected tv error_websocket_disconencted web-socket is disconnected usually occurs when user tries to send commands to tv without calling connect first, or after tv has already disconnected implement manually lower version of sdk 2 4 0 1 simple implementation guide the mobile device must get tv's mac info when connected successfully the mobile device must store certain values mac , so that the mobile device can use wake-up to power on the tv next time 2 pre-condition must mobile app should have connected successfully at least once so that tv can register mobile mac when tv is turned off, the tv status should be displayed as “{tv name} standby ” on the mobile device 3 basic ui scenario turn the tv off put to standby within 60 seconds tv disappears from the list and within 30 seconds reappears marked as " standby " select the tv the tv should start loading the tv webapp or dmp should start loading on the tv the video should start playing on the tv notecheck smart view sdk ux guideline for implementing wow api 4 api usage 1 how to get mac address service service getdeviceinfo new result<device> { @override public void onsuccess device device { if device != null string wifimac = device getwifimac ; sharedpreferences editor editor = getsharedpreferences "wowmacs", 0 edit ; editor putstring name, wifimac ; editor commit ; } @override public void onerror com samsung multiscreen error error { } } ; 2 wake up tv string mac = getsharedpreferences "wowmacs", 0 getstring service getname , 0 ; service wakeonwirelesslan mac ; 3 wake up tv and connect this api turns on the selected tv and smart view sdk confirm to be ready then, you can turn on the tv and launch your application //for connection is used default timeout service default_wow_timeout_value = 60000 string mac = getsharedpreferences "wowmacs", 0 getstring service getname , 0 ; string uri = getsharedpreferences "wowips", 0 getstring mac, 0 ; service wakeonwirelessandconnect mac, uri, new result<service> { @override public void onsuccess service service { if service != null { application application = service createapplication "your_app_id","your_channel_id" ; application connect new result<client> { @override public void onsuccess client client { if client != null { log d "log", "onsuccess " + client tostring ; } } @override public void onerror com samsung multiscreen error error { log d "log", "onerror " + error getmessage ; } } ; } } @override public void onerror com samsung multiscreen error error { log d "log", "onerror " + error getmessage ; } } ; //connect using custom timeout int timeout = 120000; service wakeonwirelessandconnect mac, uri, timeout, new result<service> { } 4 make wow tv list this is a sample code showing how to manage the tv list // create wow tv list listview wowlist = listview findviewbyid r id wowlistview ; standbylistadapter = new standbymodetvlistadapter this, r layout listview_item ; wowlist setadapter standbylistadapter ; // create available tv list listview tvlist = listview findviewbyid r id tvlistview ; tvlistadapter = new tvlistadapter this, r layout listview_item ; tvlist setadapter tvlistadapter ; // stored names and mac addresses of connected before tvs sharedpreferences wowmacs = getsharedpreferences "wowmacs", 0 ; // stored names and uri of connected before tvs sharedpreferences wowips = getsharedpreferences "wowips", 0 ; // stored mac addresses and network's ids of connected before tvs to show available tvs only sharedpreferences wowids = getsharedpreferences "wowids", 0 ; if wowmacs!=null && wowips!=null && wowids!=null { // get all stored tv's macs map<string, string> macslist = map<string, string> wowmacs getall ; // get all stored tv's names set<string> names = macslist keyset ; for string name names { // get tv mac according to name string mac = wowmacs getstring name, null ; // get tv uri according to mac string uri = wowips getstring mac, null ; // get network id according to mac int wifiid = wowids getint mac, 0 ; // check whether tv is on or off // check whether tv is in network or not if mac != null && null != uri && !tvlistadapter contains uri && wifiid == wifimanager getconnectioninfo getnetworkid { // check regarding duplicates if !listwow contains name + " standby " + mac { listwow add name + " standby " + mac ; standbylistadapter add name + " standby " + mac ; standbylistadapter notifydatasetchanged ; } } } } ble discovery bluetooth low energy you can discover a compatible samsung smart tv using bluetooth low energy network by the search class or blesearchprovider class start ble discovery to start ble discovery we need to search object to discover tv's using startusingble api of smart view sdk search search = com samsung multiscreen service search this ; search startusingble ; register listener for getting tv device list to get the discovered devices we need to register search object with setonblefoundlistener listener if ble discovers any device, it notify through onfound method of onblefoundlistener search setonblefoundlistener new search onblefoundlistener { @override public void onfoundonlyble string tvname { bletvlist add tvname ; log i tag,"tv found isactivityrunning getapplicationcontext "+isactivityrunning getapplicationcontext ; shownotification tvname ; ontimertick tvname ; } } ; stop ble discovery to stop ble discovery, call stopusingble api of smart view sdk search stopusingble ; support multitasking the default value for multitasking support is true your application should support multitasking your app will change the background state in the following circumstances launching other application over currently running application calling tizen application getcurrentapplication hide method turning off tv during application running in samsung instant on mode clicking "smart hub" button and going to the apps page your app can select one of two operation keep connection close connection keep connection webapp and mobile app keep the connection and mobile app can change the state tv app background to foreground example javascript api usage web app // support multitasking // case 2 keep connection // 1 keep connect status // 2 notify to mobile document addeventlistener "visibilitychange", function { log "app become be hide "+document hidden ; if document hidden { console log "app become be hide" ; channel publish 'visibilitychange', 'hide' ; } } ; example android api usage //1 get "visibilitychange" message //2 manage tv web app status mapplication addonmessagelistener "visibilitychange", new application onmessagelistener { @override public void onmessage message message { log d tag, "addonmessagelistener visibilitychange " + message tostring +"date = "+message getdata ; if "hide" equals message getdata { tvwebapphide = true; log d tag, "addonmessagelistener tvwebapphide " + tvwebapphide ; } } } ; //and then check tvapphide //webapp private void publish final string event, final object data { if mapplication != null { if tvwebapphide { //try to start tv web app move background to foreground mapplication start new result<boolean> { @override public void onsuccess boolean aboolean { tvwebapphide = false; mapplication publish event, data ; log d tag, "application connect onsuccess " + aboolean tostring ; } @override public void onerror error error { log d tag, "application connect onerror " + error tostring ; } } ; }else{ mapplication publish event,data ; } } } close connection disconnect webapp and mobile app just close the connection when tv web app is in the background example javascript api usage web app // 1 disconnect when webapp become background status hide // 2 and mobile app android fire callback ondisconnect and handle mobile app status document addeventlistener "visibilitychange", function { if document hidden { console log "app become be hide" ; var app = tizen application getcurrentapplication ; if app app exit ; } } ; tls make secure connection noteit need to update mobile library to use tls feature android 2 3 7 higher ios 2 3 8 higher js 2 3 3 higher smartviewsdk can make secure connection between sender and receiver through wss & http refer to latest castvideo sample app 1 setsecuritymode api public void setsecuritymode boolean securitymode, result <boolean> result set security mode status to for web socket connection or rest api parameters securitymode - security mode status to set result - result to return whether security mode was set or not 2 sample code mremoteapp setsecuritymode true, new result<boolean> { @override public void onsuccess boolean aboolean { if attributes != null { mremoteapp connect attributes, mconnectresult ; } else { mremoteapp connect mconnectresult ; } mtimeouttimer = new timer ; mtimeouttimer schedule new timeouttask , timeout ; } @override public void onerror error error { fcerror liberror = new fcerror 203, "connecting error can't create tls channel " ; for onfcerrorlistener listener mfcerrorlisteners { listener onerror liberror ; } } } ;