### Install Package Example Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/package-api.html?device=htv Demonstrates how to install a package using the tizen.package.install method. It includes callbacks for progress, completion, and error handling, and uses tizen.filesystem.resolve to get the file URI. ```javascript var onInstallation = { onprogress: function(packageId, percentage) { console.log("On installation(" + packageId + ") : progress(" + percentage + ")"); }, oncomplete: function(packageId) { console.log("Installation(" + packageId + ") Complete"); } } var onError = function (err) { console.log("Error occurred on installation : " + err.name); } // Let's assume that the "test.wgt" file exists in the downloads directory tizen.filesystem.resolve("downloads/test.wgt", function (file) { console.log("file URI : " + file.toURI()); tizen.package.install(file.toURI(), onInstallation, onError); }, function (err) { console.log("Error occurred on resolve : " + err.name); }, "r"); ``` -------------------------------- ### Get Installed Applications Example Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/application-api.html?device=signage Example of how to retrieve a list of installed applications and log their IDs. This uses the ApplicationInformationArraySuccessCallback. ```javascript function onListInstalledApps(applications) { for (var i = 0; i < applications.length; i++) console.log("ID : " + applications[i].id); } tizen.application.getAppsInfo(onListInstalledApps); ``` -------------------------------- ### Create, Connect, Disconnect, and Install TV App (Swift) Source: https://developer.samsung.com/smarttv/develop/extension-libraries/smart-view-sdk/ios-sender-app.html This example demonstrates how to create an application reference using its ID, connect to the TV application with optional attributes, disconnect, and initiate the installation process. Note that installation requires user confirmation on the TV. ```swift let appId: String = "111299000796" // Example for web app let appId: URL = URL(string: "http://yourwebapp.com") let channelID: String = "com.samsung.multiscreen.helloworld" let msApplication = service.createApplication(appID, channelURI: channelID, args: nil) msApplication.connectionTimeout = 5.0 // Attributes is optional let attr: [String:String] = ["userID":"idTest","userPW":"pwTest"] // Connect to the tv application. // Note: This will also launch the tv application if not already launched msApplication.connect(attr) // Disconnect from the application msApplication.disconnect() // 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. msApplication.install({ (success, error) -> Void in if success == true { print("Application.install Success") } else { print("Application.install Error : \(error)") } }) ``` -------------------------------- ### Get Installed Applications Example Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/application-api.html?device=htv Example of how to retrieve and log the IDs of installed applications using tizen.application.getAppsInfo. ```javascript function onListInstalledApps(applications) { for (var i = 0; i < applications.length; i++) console.log("ID : " + applications[i].id); } tizen.application.getAppsInfo(onListInstalledApps); ``` -------------------------------- ### Get Installed Applications Example Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/application-api.html?device=htv Retrieves a list of installed applications and logs their IDs. This example demonstrates the usage of ApplicationManager.getAppsInfo(). ```javascript function onListInstalledApps(applications) { for (var i = 0; i < applications.length; i++) console.log("ID : " + applications[i].id); } tizen.application.getAppsInfo(onListInstalledApps); ``` -------------------------------- ### Get Available Windows Example Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/tvwindow-api.html?device=signage Retrieves a list of available TV windows. Requires the 'http://tizen.org/privilege/tv.window' privilege. Ensure to handle potential WebAPIExceptions. ```javascript function successCB(availableWindows) { for (var i = 0; i < availableWindows.length; i++) { console.log("Window ["+ i + "] = " + availableWindows[i]); } } try { tizen.tvwindow.getAvailableWindows(successCB); } catch (error) { console.log("Error name = "+ error.name + ", Error message = " + error.message); } ``` -------------------------------- ### Filesystem Example Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/filesystem-api.html?device=htv This code example demonstrates how to resolve a directory ('documents'), list its files, and then delete each file found. It includes success and error callbacks for both resolving the directory and listing files. ```JavaScript var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { if (!files[i].isDirectory) { documentsDir.deleteFile(files[i].fullPath, function() { console.log("File Deleted"); }, function(e) { console.log("Error " + e.message); }); } } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "rw"); ``` -------------------------------- ### Application Installation Code Flow Source: https://developer.samsung.com/smarttv/develop/extension-libraries/smart-view-sdk/android-sender-app/enhanced-features.html This comprehensive code flow illustrates the process of creating an application instance, retrieving its information, and conditionally installing it if it's not found. It also shows how to connect to the application after installation. ```Java //1. Create Appication mApplication = mService.createApplication(mApplicationId, mChannelId); //2. Get AppicationInfo if you need mApplication.getInfo(new Result() { @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() { @Override public void onSuccess(Boolean result) { Log.d(LOGTAG, "Application.install onSuccess() " + result.toString()); } }); } } }); //3. Launch installed app mApplication.connect(new Result() { @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() { @Override public void onSuccess(Boolean result) { Log.d(LOGTAG, "Application.install onSuccess() " + result.toString()); } }); } } }); ``` -------------------------------- ### Get Remaining Seconds for Alarm Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/alarm-api.html?device=signage Example of getting the remaining seconds before the next alarm trigger using getRemainingSeconds(). ```javascript // Gets the current application ID. var appId = tizen.application.getCurrentApplication().appInfo.id; // Sets an alarm in 3 hours from now var alarm = new tizen.AlarmRelative(3 * tizen.alarm.PERIOD_HOUR); tizen.alarm.add(alarm, appId); var sec = alarm.getRemainingSeconds(); console.log("remaining time is " + sec); ``` -------------------------------- ### Get Information of Installed Packages Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/package-api.html?device=htv Retrieves and logs the IDs of all installed packages on the device. This is useful for inventorying applications. ```javascript function onListInstalledPackages(packages) { for (var i = 0; i < packages.length; i++) { console.log("Package id["+i+"] : " +packages[i].id); } } tizen.package.getPackagesInfo( onListInstalledPackages, function (err) {console.log("Can't obtain packages list" + err.name);}); ``` -------------------------------- ### Create, Connect, Disconnect, and Install TV App Source: https://developer.samsung.com/SmartTV/develop/extension-libraries/smart-view-sdk/ios-sender-app.html This snippet demonstrates the core functions for interacting with a TV application: creating an application reference, connecting to it with optional attributes, disconnecting, and initiating installation. It shows how to handle both installed and web applications using their respective IDs or URLs. ```swift let appId: String = "111299000796" // Example for web app let appId: URL = URL(string: "http://yourwebapp.com") let channelID: String = "com.samsung.multiscreen.helloworld" let msApplication = service.createApplication(appID, channelURI: channelID, args: nil) msApplication.connectionTimeout = 5.0 // Attributes is optional let attr: [String:String] = ["userID":"idTest","userPW":"pwTest"] // Connect to the tv application. // Note: This will also launch the tv application if not already launched msApplication.connect(attr) // Disconnect from the application msApplication.disconnect() // 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. msApplication.install({ (success, error) -> Void in if success == true { print("Application.install Success") } else { print("Application.install Error : \(error)") } }) ``` -------------------------------- ### Install TV Application Source: https://developer.samsung.com/smarttv/develop/extension-libraries/smart-view-sdk/android-sender-app.html Initiate the installation process for the TV application. This action will display the installation page on the TV, requiring user confirmation via the remote control to complete the installation. ```java // 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() { @Override public void onSuccess(Boolean result) { Log.d(LOGTAG, "Application.install onSuccess() " + result.toString()); } @Override public void onError(Error error) { Log.d(LOGTAG, "Application.install onError() " + error.toString()); // Uh oh. Handle the error. } }); ``` -------------------------------- ### addAppInfoEventListener Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/application-api.html?device=signage Installs a callback that is triggered when there is a change in the list of installed applications (installation, uninstallation, or update). It returns a listener ID that can be used to remove the listener later. The change detection starts asynchronously. ```APIDOC ## addAppInfoEventListener ### Description Installs a callback that is triggered every time a change occurs on the list of installed applications on a device. This change may occur due to a new installation, uninstallation, or update of an application. ### Method ```javascript tizen.application.addAppInfoEventListener(eventCallback) ``` ### Parameters #### Path Parameters * **eventCallback** (ApplicationInformationEventCallback) - The method to call when a change on the installed applications is made. ### Return Value * **long** - ID of the listener that can be used to remove the listener later. ### Exceptions * **WebAPIException** * TypeMismatchError: If any input parameter is not compatible with the expected type. * UnknownError: If it fails to add a listener due to an unknown error. ### Example ```javascript var appEventCallback = { oninstalled: function(appInfo) { console.log('The application ' + appInfo.name + ' is installed'); }, onupdated: function(appInfo) { console.log('The application ' + appInfo.name + ' is updated'); }, onuninstalled: function(appid) { console.log('The application ' + appid + ' is uninstalled'); } }; var watchId = tizen.application.addAppInfoEventListener(appEventCallback); ``` ``` -------------------------------- ### Image Role Example - Tizen Voice Guide Source: https://developer.samsung.com/SmartTV/develop/guides/fundamentals/text-to-speech.html?device=signage Details the voice guide output for an image with an ARIA 'img' role in Tizen 4.0. ```text Tizen | **Tizen 4.0** : * The voice guide says: "American Express, image". ``` -------------------------------- ### Start Download with Event Handlers Source: https://developer.samsung.com/SmartTV/develop/guides/data-handling/downloading-data.html Initiate a download and define callback functions to handle progress, pausing, cancellation, completion, and failure events. ```javascript tizen.download.start(download_obj, { onprogress: function(id, receivedSize, totalSize) { console.log(id); console.log(receivedSize); console.log(totalSize); }, onpaused: function(id) { console.log(id); }, oncanceled: function(id) { console.log(id); }, oncompleted: function(id, fullPath) { console.log(id); console.log(fullPath); }, onfailed: function(id, error) { console.log(id); console.log(JSON.stringify(error)); } }); ``` -------------------------------- ### NaCl Manifest File Example Source: https://developer.samsung.com/SmartTV/develop/extension-libraries/nacl/getting-started.html Defines the URLs for native binary files (.nexe) for different architectures. Ensure the ARM architecture is included for Samsung Smart TV deployment. ```json { "program": { "x86-32": { "url": "application_i686.nexe" }, "x86-64": { "url": "application_x86-64.nexe" }, "arm": { "url": "application_armv7.nexe" } } } ``` -------------------------------- ### Get Installed Applications Info Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/application-api.html?device=htv Fetches information about all installed applications on the device. The success callback receives an array of application information objects. ```javascript function onListInstalledApps(applications) { for (var i = 0; i < applications.length; i++) console.log("ID : " + applications[i].id); } tizen.application.getAppsInfo(onListInstalledApps); ``` -------------------------------- ### Example: Creating a Player Instance Source: https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/avplaystore-api.html Demonstrates how to obtain an AVPlayManagerObject instance using the webapis.avplaystore.getPlayer() method. ```javascript var playerinstance = webapis.avplaystore.getPlayer(); ``` -------------------------------- ### Image Role Example - Tizen 3.0 Voice Guide Source: https://developer.samsung.com/SmartTV/develop/guides/fundamentals/text-to-speech.html?device=signage Details the voice guide output for an image with an ARIA 'img' role in Tizen 3.0. ```text **Tizen 3.0** : * The voice guide says: "Image, American Express". ``` -------------------------------- ### Create Playlist and Add Content Example Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/content-api.html Creates a new playlist, finds audio content, adds the first found content to the playlist, and then retrieves all playlists. Handles success and failure for each operation. ```javascript var gPlaylists; var gPlaylist; function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err.message); } function getPlaylistsSuccess(playlists) { var cur, i; gPlaylists = playlists; for(i = 0; i < gPlaylists.length; ++i) { cur = gPlaylists[i]; console.log("[" + i + "] name:" + cur.name + " num tracks:" + cur.numberOfTracks); } } function findSuccess(contents) { if (contents.length > 0) { gPlaylist.add(contents[0]); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail); } function findFail(err) { console.log("find FAIL: " + err.message); } function createSuccess(playlist) { console.log("create SUCCESS"); gPlaylist = playlist; tizen.content.find(findSuccess, findFail, null, new tizen.AttributeFilter("type", "EXACTLY", "AUDIO")); } function createFail(err) { console.log("create FAIL: " + err.message); } tizen.content.createPlaylist("My new playlist", createSuccess, createFail); ``` -------------------------------- ### Checkbox Example (Mixed-State) - Tizen Voice Guide Source: https://developer.samsung.com/SmartTV/develop/guides/fundamentals/text-to-speech.html?device=signage Illustrates the voice guide behavior for checkboxes in Tizen 4.0, noting that state changes are not announced. ```text Tizen | **Tizen 4.0** : * When the "Lettuce" checkbox has focus, the voice guide says: "Lettuce, not selected". * When the "Tomato" checkbox has focus, the voice guide says: "Tomato, selected". * When the checkbox state is changed, the voice guide does not read the checkbox state. **Tizen 3.0** : * Not supported. **Tizen 2.4** : * Same behavior as on Tizen 4.0. ``` -------------------------------- ### Start Download and Handle Events Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/download-api.html Initiates a file download and sets up a listener for progress, completion, and error events. It also demonstrates how to check for Wi-Fi support and attempt a Wi-Fi specific download. ```javascript // Check if Download API is supported not on a device. var download_api_capability = tizen.systeminfo.getCapability("http://tizen.org/feature/download"); if (download_api_capability === false) { console.log("Download API is not supported on this device."); return; } var listener = { onprogress: function(id, receivedSize, totalSize) { console.log('Received with id: ' + id + ', ' + receivedSize + '/' + totalSize); }, onpaused: function(id) { console.log('Paused with id: ' + id); }, oncanceled: function(id) { console.log('Canceled with id: ' + id); }, oncompleted: function(id, path) { console.log('Completed with id: ' + id + ', path: ' + path); }, onfailed: function(id, error) { console.log('Failed with id: ' + id + ', error name: ' + error.name); } }; // Starts downloading the file from the Web with the corresponding callbacks. var downloadRequest = new tizen.DownloadRequest("http://download.tizen.org/tools/README.txt", "documents"); var downloadId = tizen.download.start(downloadRequest, listener); // If you want to download a large file through Wi-Fi, var wifi_capability = tizen.systeminfo.getCapability("http://tizen.org/feature/network.wifi"); var wifiDownloadRequest = new tizen.DownloadRequest("http://download.tizen.org/tools/archive/14.02.2/Ubuntu_12.04/qemu_1.6.0rc3.orig.tar.gz", "downloads", null, "WIFI"); if (wifi_capability === true) { var downlodId_wifi = tizen.download.start(wifiDownloadRequest, listener); } else { // If you call tizen.download.start(), NotSupportedError will be thrown. console.log("This device doesn't support Download API through Wi-Fi."); } ``` -------------------------------- ### Modal Dialog Example - Tizen Voice Guide Source: https://developer.samsung.com/SmartTV/develop/guides/fundamentals/text-to-speech.html?device=signage Describes the voice guide behavior for a modal dialog in Tizen 4.0, highlighting that the dialog box title is not read. ```text Tizen | **Tizen 4.0** : * Same behavior as the reference implementation, but the voice guide does not read the dialog box title. ``` -------------------------------- ### Install Application if Not Found Source: https://developer.samsung.com/SmartTV/develop/extension-libraries/smart-view-sdk/ios-sender-app/enhanced-features.html This code snippet demonstrates how to check if an application exists on the TV and initiate its installation if it's not found. It uses the getInfo() or connect() methods, and if an error code of 404 is received, it calls the install() API. Note that this only brings up the installation page on the TV; the user must confirm the installation. ```java //1. Create Appication mApplication = mService.createApplication(mApplicationId, mChannelId); //2. Get AppicationInfo if you need mApplication.getInfo(new Result() { @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() { @Override public void onSuccess(Boolean result) { Log.d(LOGTAG, "Application.install onSuccess() " + result.toString()); } }); } } }); //3. Launch installed app mApplication.connect(new Result() { @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() { @Override public void onSuccess(Boolean result) { Log.d(LOGTAG, "Application.install onSuccess() " + result.toString()); } }); } } }); ``` -------------------------------- ### TTS with Nested Elements Source: https://developer.samsung.com/SmartTV/develop/guides/fundamentals/text-to-speech.html?device=htv The voice guide reads the content of a focused HTML element, including its child elements. This example shows how nested elements are read by the voice guide. ```html
TTS Test
Second Element.
``` -------------------------------- ### Install a Package Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/package-api.html?device=htv Installs a package from a given URI. The installation progress and completion can be monitored via a callback, and errors are handled by another callback. ```APIDOC ## install ### Description Installs a package with a specified file on a device. This API provides a way to notify the progress and completion of an installation request through PackageProgressCallback. ### Method ``` void install(DOMString packageFileURI, PackageProgressCallback progressCallback, optional ErrorCallback? errorCallback) ``` ### Parameters * **packageFileURI** (DOMString) - The location of the package to install. * **progressCallback** (PackageProgressCallback) - The method to invoke when the installation is in progress or has been completed. * **errorCallback** (optional, nullable ErrorCallback) - The method to invoke when an error occurs. ### Exceptions * **WebAPIException** * TypeMismatchError: If any input parameter is not compatible with the expected type. * SecurityError: If the application does not have the privilege to call this method. ### Privilege * **http://tizen.org/privilege/packagemanager.install** ### Remarks Virtual paths cannot be used. Convert virtual paths to file URIs using the Filesystem API's resolve function first. ### Code Example ```javascript var onInstallation = { onprogress: function(packageId, percentage) { console.log("On installation(" + packageId + ") : progress(" + percentage + ")"); }, oncomplete: function(packageId) { console.log("Installation(" + packageId + ") Complete"); } } var onError = function (err) { console.log("Error occurred on installation : " + err.name); } // Assuming "test.wgt" exists in the downloads directory tizen.filesystem.resolve("downloads/test.wgt", function (file) { console.log("file URI : " + file.toURI()); tizen.package.install(file.toURI(), onInstallation, onError); }, function (err) { console.log("Error occurred on resolve : " + err.name); }, "r"); ``` ``` -------------------------------- ### Package API Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references.html Provides information install/uninstall package and get information about installed packages. ```APIDOC ## Package API ### Description This API provides information install/uninstall package and get information about installed packages. ### Version 2.1 ### Supported on TV Mandatory ### Supported on Emulator Yes ``` -------------------------------- ### Example: Set Volume Up and Check Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/tvaudiocontrol-api.html?device=htv Demonstrates setting the volume and then increasing it using setVolumeUp(), checking if the volume reaches the maximum level. Deprecated privilege http://tizen.org/privilege/tv.audio (public level) since Tizen 5.0. ```javascript // Sets the volume tizen.tvaudiocontrol.setVolume(99); tizen.tvaudiocontrol.setVolumeUp(); // Check if the current volume is 100 or not. if (tizen.tvaudiocontrol.getVolume() === 100) { alert("setVolumeUp() is successfully called."); } tizen.tvaudiocontrol.setVolumeUp(); // Check if the volume level has been changed or not at the maximum volume level. if (tizen.tvaudiocontrol.getVolume() === 100) { alert("setVolumeUp() is successfully called."); } ``` -------------------------------- ### Get Caption Value Example Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/tvinfo-api.html Demonstrates how to retrieve the current state of a caption setting. ```javascript console.log("Caption menu turned on: " + (tizen.tvinfo.getCaptionValue("CAPTION_ONOFF_KEY") === "CAPTION_ON")); ``` -------------------------------- ### Create File, Open Stream, Write, and Close Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/filesystem-api.html?device=signage Creates a file named 'test.txt' in the 'documents' directory, opens it in write mode with UTF-8 encoding, writes 'HelloWorld' to it, and then closes the stream. This demonstrates basic file creation and content writing. ```javascript var documentsDir; function onsuccess(files) { for (var i = 0; i < files.length; i++) { console.log("File Name is " + files[i].name); /* Displays file name. */ } var testFile = documentsDir.createFile("test.txt"); if (testFile != null) { testFile.openStream("w", function(fs) { fs.write("HelloWorld"); fs.close(); }, function(e) { console.log("Error " + e.message); }, "UTF-8"); } } function onerror(error) { console.log( "The error " + error.message + " occurred when listing the files in the selected folder"); } tizen.filesystem.resolve("documents", function(dir) { documentsDir = dir; dir.listFiles(onsuccess, onerror); }, function(e) { console.log("Error " + e.message); }, "rw"); ``` -------------------------------- ### Get Package Information Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/package-api.html?device=signage Retrieves information for all installed packages or a specific package by its ID. ```APIDOC ## getPackagesInfo ### Description Retrieves information for all installed packages. ### Method ``` void getPackagesInfo(PackageInformationArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) ``` ### Parameters * **successCallback** (PackageInformationArraySuccessCallback) - The callback function to be invoked with an array of PackageInformation objects. * **errorCallback** (optional, nullable ErrorCallback) - The method to invoke when an error occurs. ### Exceptions * **WebAPIException** * SecurityError - if the application does not have the privilege to call this method. ## getPackageInfo ### Description Retrieves information for a specific package by its ID, or the current application's package information if no ID is provided. ### Method ``` PackageInformation getPackageInfo(optional PackageId? id) ``` ### Parameters * **id** (optional, nullable PackageId) - The ID of the package to retrieve information for. If omitted, information for the current application is returned. ### Exceptions * **WebAPIException** * TypeMismatchError - if the input parameter is not compatible with the expected type. * SecurityError - if the application does not have the privilege to call this method. ``` -------------------------------- ### Layout Grid Examples - Tizen Voice Guide Source: https://developer.samsung.com/SmartTV/develop/guides/fundamentals/text-to-speech.html?device=signage Explains the voice guide behavior for grid elements in Tizen 4.0, including navigation within the grid and focus movement considerations. ```text Tizen | **Tizen 4.0** : * When a grid item has focus, the voice guide only reads the grid item content. * To navigate within the grid, use the arrow keys. However, JavaScript consumes the arrow key events, so you must consider how to implement navigating away from the grid. * Within the Web browser, navigation between grid items can have unintended behavior, such as focus moving twice when the arrow key is clicked once. * Because `grid` is a composite UI element, and there is no "Tab" key on a remote control, you must consider how to implement focus movement to descendants. **Tizen 3.0** : * Same behavior as on Tizen 4.0. **Tizen 2.4** : * Not supported. When a grid item has focus, the voice guide only reads the grid item content. ``` -------------------------------- ### Launch Application with Success and Error Callbacks Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/tizen-api.html Example demonstrating how to launch an application and handle both successful launches and errors using separate callbacks. ```javascript // Define the error callback. function onerror(error) { console.log(error.message); } function onSuccess() { console.log("The application has launched successfully"); } tizen.application.launch("targetApp0.main", onsuccess, onerror); ``` -------------------------------- ### Install Web App if Not Found Source: https://developer.samsung.com/smarttv/develop/extension-libraries/smart-view-sdk/ios-sender-app/enhanced-features.html This code flow demonstrates how to check if a web app exists on the TV using getInfo() or connect(). If a 404 error is received, it triggers the installation process for the app. The install() API only brings up the installation page; user confirmation is still required on the TV. ```java mApplication = mService.createApplication(mApplicationId, mChannelId); mApplication.getInfo(new Result() { @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() { @Override public void onSuccess(Boolean result) { Log.d(LOGTAG, "Application.install onSuccess() " + result.toString()); } }); } } }); //3. Launch installed app mApplication.connect(new Result() { @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() { @Override public void onSuccess(Boolean result) { Log.d(LOGTAG, "Application.install onSuccess() " + result.toString()); } }); } } }); ``` -------------------------------- ### Install Package Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/package-api.html Installs a package from a given URI. The installation progress and completion are reported via callbacks, and errors are handled by an optional error callback. ```APIDOC ## POST /package/install ### Description Installs a package with a specified file on a device. This API provides a way to notify the progress and completion of an installation request through PackageProgressCallback. ### Method POST ### Endpoint /package/install ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **packageFileURI** (DOMString) - Required - The location of the package to install. * **progressCallback** (PackageProgressCallback) - Required - The method to invoke when the installation is in progress or has been completed. * **errorCallback** (optional ErrorCallback) - Optional - The method to invoke when an error occurs. ### Request Example ```javascript var onInstallation = { onprogress: function(packageId, percentage) { console.log("On installation(" + packageId + ") : progress(" + percentage + ")"); }, oncomplete: function(packageId) { console.log("Installation(" + packageId + ") Complete"); } } var onError = function (err) { console.log("Error occurred on installation : " + err.name); } // Let's assume that the "test.wgt" file exists in the downloads directory tizen.filesystem.resolve("downloads/test.wgt", function (file) { console.log("file URI : " + file.toURI()); tizen.package.install(file.toURI(), onInstallation, onError); }, function (err) { console.log("Error occurred on resolve : " + err.name); }, "r"); ``` ### Response #### Success Response (200) Installation initiated successfully. Progress and completion are handled via callbacks. #### Response Example None (asynchronous operation with callbacks) ``` -------------------------------- ### Checkbox Example (Mixed-State) - Tizen Behavior Source: https://developer.samsung.com/smarttv/develop/guides/fundamentals/text-to-speech.html Demonstrates the voice guide output for a checkbox with mixed states on Tizen 4.0. Note that the voice guide does not announce state changes when the checkbox is toggled. ```text Tizen | **Tizen 4.0** : * When the "Lettuce" checkbox has focus, the voice guide says: "Lettuce, not selected". * When the "Tomato" checkbox has focus, the voice guide says: "Tomato, selected". * When the checkbox state is changed, the voice guide does not read the checkbox state. **Tizen 3.0** : * Not supported. **Tizen 2.4** : * Same behavior as on Tizen 4.0. ``` -------------------------------- ### Install Application on TV Source: https://developer.samsung.com/smarttv/develop/extension-libraries/smart-view-sdk/android-sender-app/enhanced-features.html This code snippet demonstrates how to initiate the installation of an application on a Samsung Smart TV. It's used when an application is not found (onError code 404) after attempting to get its info or connect to it. Note that this action only brings up the installation page on the TV; user confirmation is still required. ```Java mApplication.install(new Result() { @Override public void onSuccess(Boolean result) { Log.d(LOGTAG, "Application.install onSuccess() " + result.toString()); } }); ``` -------------------------------- ### DownloadRequest Example with HTTP Headers Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/download-api.html Demonstrates creating a DownloadRequest and setting custom HTTP headers for the download. ```javascript var req = new tizen.DownloadRequest("http://download.tizen.org/tools/README.txt"); req.httpHeader["Pragma"] = "no-cache"; req.httpHeader["Cookie"] = "version=1; Skin=new"; req.httpHeader["X-Agent"] = "Tizen Sample App"; ``` -------------------------------- ### Get Playlist Items Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/content-api.html?device=htv Retrieves playlist items from a specified playlist. You can control the number of items and the starting offset. ```APIDOC ## get ### Description Gets playlist items from a playlist. ### Method void get(PlaylistItemArraySuccessCallback successCallback, optional ErrorCallback? errorCallback, optional long? count, optional long? offset) ### Parameters * **successCallback** (PlaylistItemArraySuccessCallback) - Callback method to be invoked for a list of tracks in the playlist. * **errorCallback** (optional, nullable) (ErrorCallback?) - Callback method to be invoked when an error occurs. * **count** (optional, nullable) (long?) - Number of playlist items to return. If not passed, all playlist items are retrieved. * **offset** (optional, nullable) (long?) - Offset of the track from the beginning of the playlist. The default value is 0. ### Exceptions * **WebAPIException** * TypeMismatchError: If any input parameter is not compatible with the expected type. * SecurityError: If the application does not have the required privilege. ### Privilege http://tizen.org/privilege/content.read ### Error Types * **InvalidValuesError**: If any of the input parameters contain an invalid value (e.g., _count_ or _offset_ is a negative number). * **UnknownError**: In case of any error. ``` -------------------------------- ### ASFService Browse Example Source: https://developer.samsung.com/SmartTV/develop/api-references/samsung-product-api-references/asfservice-api.html Demonstrates browsing media content with a specified filter and sort mode. Includes callback definitions for success and error. ```javascript var serviceProvider = webapis.allshare.serviceconnector.getServiceProvider(); // Define a browse callback function browseCB(list, endOfItem, providerId) { // Retrieve the item list } function errorCB(error, deviceId) { console.log(error.message); } // Define a filter to browse videos only var filter = new webapis.AttributeFilter("itemType", null, {"VIDEO"}); // Define a sort mode var mode = new webapis.SortMode("title", "ASC"); ``` -------------------------------- ### Get Playlists Example Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/content-api.html Retrieves all playlists and logs their names and track counts. Handles success and failure callbacks. ```javascript var gPlaylists; function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { var cur, i; gPlaylists = playlists; for(i = 0; i < gPlaylists.length; ++i) { cur = gPlaylists[i]; console.log("[" + i + "] name:" + cur.name + " num tracks:" + cur.numberOfTracks); } } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail); ``` -------------------------------- ### Core Functions for Working with Installed TV Apps Source: https://developer.samsung.com/smarttv/develop/extension-libraries/smart-view-sdk/ios-sender-app.html This section details the primary functions for interacting with TV applications: creating an application reference, connecting to the application, disconnecting, and installing the application. It also provides an example of how to use these functions in Swift. ```APIDOC ## Service.createApplication ### Description Creates an application reference to your TV app using its app ID and channel ID. ### Method Signature `Service.createApplication(id: AnyObject, channelURI: String, args: [String:AnyObject]?) -> AnyObject` ### Parameters - **id** (AnyObject) - The unique identifier of the TV application. This can be a String for released apps or a URL for web apps. - **channelURI** (String) - The channel URI for the TV application. - **args** ([String:AnyObject]?) - Optional dictionary of arguments to pass when creating the application reference. --- ## application.connect ### Description Connects to the TV application. This action will also launch the TV application if it is not already running. ### Method Signature `application.connect(attributes: [String:String]?)` ### Parameters - **attributes** ([String:String]?) - Optional dictionary of attributes to use for the connection. --- ## application.disconnect ### Description Disconnects from the TV application. ### Method Signature `application.disconnect()` --- ## application.install ### Description Initiates the installation process for the TV application on the TV. Note that this action only brings up the installation page on the TV, and the user must still confirm the installation using the TV remote. This function only supports installed apps and does not support Web Applications. ### Method Signature `application.install(completionHandler: ((success: Bool, error: NSError?) -> Void)?)` ### Parameters - **completionHandler** ((success: Bool, error: NSError?) -> Void)? - A closure that is called upon completion of the installation attempt, providing a success status and an optional error object. --- ## Swift Example Usage ### Description An example demonstrating how to use the `createApplication`, `connect`, `disconnect`, and `install` methods in Swift. ### Code ```swift // Example for installed app let appId: String = "111299000796" // Example for web app // let appId: URL = URL(string: "http://yourwebapp.com") let channelID: String = "com.samsung.multiscreen.helloworld" // Assuming 'service' is an initialized instance of the Service class let msApplication = service.createApplication(appId, channelURI: channelID, args: nil) msApplication.connectionTimeout = 5.0 // Attributes is optional let attr: [String:String] = ["userID":"idTest","userPW":"pwTest"] // Connect to the tv application. // Note: This will also launch the tv application if not already launched msApplication.connect(attr) // Disconnect from the application msApplication.disconnect() // 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. msApplication.install { (success, error) -> Void in if success == true { print("Application.install Success") } else { print("Application.install Error : \(error)") } } ``` ``` -------------------------------- ### Image Example - Tizen 3.0 Source: https://developer.samsung.com/smarttv/develop/guides/fundamentals/text-to-speech.html?device=signage Describes the voice guide output for an image on Tizen 3.0, which reads 'Image' followed by the aria-label. ```text * The voice guide says: "Image, American Express". ``` -------------------------------- ### Example: Finding and Launching an Application Control Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/application-api.html?device=signage Demonstrates how to create an ApplicationControl, find matching applications using findAppControl, and then launch the first found application using launchAppControl. Includes handling replies from the launched application. ```javascript var appControl = new tizen.ApplicationControl( "http://tizen.org/appcontrol/operation/pick", null, "image/jpeg", null); // FindAppControlSuccessCallback instance function successCB(appInfos, appControl) { // appControl is same object with the value passed as first parameter to findAppControl() var appControlReplyCallback = { // callee sent a reply onsuccess: function(data) { for (var i = 0; i < data.length; i++) { if (data[i].key == "http://tizen.org/appcontrol/data/selected") { console.log('Selected image is ' + data[i].value[0]); } } }, // callee returned failure onfailure: function() { console.log('The launch application control failed'); } } var appId = appInfos[0].id; // select first app's id tizen.application.launchAppControl( appControl, appId, function() {console.log("launch application control succeed"); }, function(e) {console.log("launch application control failed. reason: " + e.message); }, appControlReplyCallback ); } tizen.application.findAppControl(appControl, successCB); ``` -------------------------------- ### Image Example - Tizen 4.0 Source: https://developer.samsung.com/smarttv/develop/guides/fundamentals/text-to-speech.html?device=signage Details the voice guide output for an image on Tizen 4.0, which reads the aria-label followed by 'image'. ```text * The voice guide says: "American Express, image". ``` -------------------------------- ### Install a Package Source: https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/package-api.html?device=signage Installs a package from a given URI. It provides callbacks for progress and completion, as well as error handling. ```APIDOC ## install ### Description Installs a package with a specified file on a device. This API provides a way to notify the progress and completion of an installation request through PackageProgressCallback. The ErrorCallback() is launched with these error types: NotFoundError - If the package is not found at the specified location. UnknownError - If it is not allowed to install the package by the platform or any other platform error occurs. ### Method ``` void install(DOMString packageFileURI, PackageProgressCallback progressCallback, optional ErrorCallback? errorCallback) ``` ### Parameters * **packageFileURI** (DOMString) - The location of the package to install * **progressCallback** (PackageProgressCallback) - The method to invoke when the installation is in progress or has been completed * **errorCallback** (optional, nullable ErrorCallback) - The method to invoke when an error occurs ### Exceptions * **WebAPIException** * TypeMismatchError - if any input parameter is not compatible with the expected type for that parameter. * SecurityError - if the application does not have the privilege to call this method. ### Privilege * **Level**: platform * **Name**: http://tizen.org/privilege/packagemanager.install ### Remark Virtual path cannot be used for the parameter. First, you need to convert any virtual path to a file URI path using the resolve function in the Filesystem API before passing it to the function. ### Code example ```javascript var onInstallation = { onprogress: function(packageId, percentage) { console.log("On installation(" + packageId + ") : progress(" + percentage + ")"); }, oncomplete: function(packageId) { console.log("Installation(" + packageId + ") Complete"); } } var onError = function (err) { console.log("Error occurred on installation : " + err.name); } // Let's assume that the "test.wgt" file exists in the downloads directory tizen.filesystem.resolve("downloads/test.wgt", function (file) { console.log("file URI : " + file.toURI()); tizen.package.install(file.toURI(), onInstallation, onError); }, function (err) { console.log("Error occurred on resolve : " + err.name); }, "r"); ``` ``` -------------------------------- ### Get and Remove Playlist Example Source: https://developer.samsung.com/SmartTV/develop/api-references/tizen-web-device-api-references/content-api.html Demonstrates how to retrieve all playlists and then remove the first one. Ensure the playlist exists before attempting removal. ```javascript var gPlaylists; function removePlaylistSuccess() { console.log("removePlaylist SUCCESS"); } function removePlaylistFail(err) { console.log("removePlaylist FAIL: " + err); } function getPlaylistsFail(err) { console.log("getPlaylists failed: " + err); } function getPlaylistsSuccess(playlists) { var cur, i; gPlaylists = playlists; for(i = 0; i < gPlaylists.length; ++i) { cur = gPlaylists[i]; console.log("[" + i + "] name:" + cur.name + " num tracks:" + cur.numberOfTracks); } if(gPlaylists.length < 1) { console.log("Please add at least 1 playlist"); return; } console.log("will remove playlist at index [0] name:" + gPlaylists[0].name); tizen.content.removePlaylist(gPlaylists[0].id, removePlaylistSuccess, removePlaylistFail); } tizen.content.getPlaylists(getPlaylistsSuccess, getPlaylistsFail); ```