Search code examples
apifilesystemsmounttizensamsung-smart-tv

How to access external Storage in Tizen Smart TVs


I need yout help to find out how to write and read files from external usb storage from Tizen Smart TVs. Problem starts when detecting it

`
/**
 * Hello World Sample Project
 */
// import Label component
var Label = caph.require('ui.base.component.Label');

caph.app.addScene('main', $class({
    $extends : caph.require('ui.base.Scene'),

    // oncreate is called when the scene is created
    oncreate : function() {
        // add "Hello World"

        this.addChild(new Label({
            text : 'Hello World',
            size : [ 500, 100 ],
            position : [ 300, 400 ]
        }).setTextSize('72px').setStyle({
            backgroundColor : 'red',
            color : 'white'
        }));

        /// Here the filesystem showd show me all the storages
        tizen.filesystem.listStorages(checkCorruptedRemovableDrives);
    }
})).run();
`

And here is the Success callback, this show me how much storages I have. ` /* Success event handler */ var checkCorruptedRemovableDrives = function(storages) {

    /// Here I will kow how much storages I have
    console.log(storages.length);

    for (var i = 0; i < storages.length; i++) {
        if (storages[i].type != "EXTERNAL")
            continue;
        if (storages[i].state == "UNMOUNTABLE")
            console.log("External drive " + storages[i].label + " is corrupted.");
    }
};
`

Here is the method thrown when there are errors, this is never called. var checkCorruptedRemovableDrivesError = function(storages){ console.log("Error"); }

Now, the console output is aways a simple 0 meanning I have no storage (but I have the internal one and two usb ones mounted).

Has Anyone faced this problem or have any Idea on how to solve it?


Solution

  • Samsung Tizen TV always uses "removable2" as label for USB. So you don't need to use listStorage and getStorage.

    Multiple USBs are distinguished as "removable2/sda1", "removable2/sda2"

    tizen.filesystem.resolve("removable2", function(e){
            e.listFiles(function(r){
                for(i = 0; i < r.length; i++){
                    tizen.filesystem.resolve(r[i].path + r[i].name, function(t){
                        //You resolve USB root. Do something you want with USB.
                    }, function(t){
                        console.log("resolve error for " + r[i].path + r[i].name);
                        console.log(t);                
                    }, "rw"); //you should use rw permission, to write something in usb.
                }
            });               
        },function(e){
            console.log("removable2 resolve error");
            console.log(e);
        }, "r"); // permission should be given as r for removable2
    

    Here is test app made by me. and you can check how to use SDK 1.5

    http://www.samsungdforum.com/SamsungDForum/ForumView/3ad8bd6023af18a7?forumID=d88a711f47dc6e9f

    This app is working in both of TV and SDK 1.5