Samsung Electronics logo

Managing Content



Learning how to view content details and update them is a basic content management skill:

  1. Retrieve the ContentManager interface instance using the webapis global object, and search for the item whose details you want to update.

    In the following example, the item whose title is image7.jpg is retrieved.

    var manager = webapis.content;
    	
    var filter = new webapis.AttributeFilter("title", "EXACTLY", "image7.jpg");
    manager.find(onMediaItemArraySuccess, onError, null, filter);
  2. In the success event handler of the find() method, view the content item details by displaying them in the console log:
    function onMediaItemArraySuccess(item) 
    {
       if (item.length > 0) 
       {
          console.log(item[0].type + ":" + item[0].title + ":" + item[0].mimeType);
          console.log("geolocation-latitude :" + item[0].geolocation.latitude + " longitude:" + item[0].geolocation.longitude);
       }
       update(item[0]);
    }
  3. To update the editable attributes of the content item, use the update() method. In the example below, the rating of the content item is increased.

    function update(item)
    {
       /* Checks whether the attribute is editable */
       if (item.editableAttributes.indexOf("rating") >= 0)
       {
          /* Changes an attribute */
          item.rating = 1;
    
          /* Updates the item */
          manager.update(item); 
       } 
    }
  4. To scan for the content item file, use the scanFile() method. Because scanning is not performed automatically when the content file is copied or moved, call the scanFile() method to find the file.

    /* Assume the file:///opt/usr/media/Images/photo.jpg is inserted to the device */
    function onScanSuccessCallback(path)
    {
       console.log("Scanning completed:" + path);
    }
    var file = "file:///opt/usr/media/Images/photo.jpg";
    webapis.content.scanFile(file, onScanSuccessCallback);