[Wearable] Read/Write Widget Content

[Wearable] Read/Write Widget Content

BY 19 Mar 2017 Web Application Development
Hi, I have a wearable web app that has a widget and I want this widget to be customizable. I followed the following guide to read/write data per widget instance: https://developer.tizen.org/development/api-references/web-application?redirect=https://developer.tizen.org/dev-guide/2.3.2/org.tizen.web.apireference/html/device_api/wearable/tizen/widgetservice.html#WidgetInstance::sendContent
Unfortunately this does not work but I also do not get an error or anything. What I do in my prototype is the following:
1) retrieve all widgets and then all instances of them.
2) I then send some test data to this instances using sendContent -> which seems fine as I do not get any errors
3) After that I try to read the content from each instance using getContent -> I dont get an error but the returned object is empty and not what I’ve sent before
Note:
 – Yes I have set the required privileges, otherwise the code throws exceptions.
 – Yes there is a sample for that, but a) not for wearables and b) it does not work anyway.
With Tizen 2.3.1 for wearables there was already a bug where the widget instanced did not had different id’s – Is this just the next bug (if so: who the f*ck is testing this code?!?=) or am I doing something wrong?
Here is my code:
contentSuccessCb = function(data) {
  console.log(“Data has been obtained successfully”);
  for (var prop in data) {
    alert(prop + ” : ” + data[prop]);
  }
 }
 contentErrorCb = function(error) {
  alert(“Error occurred: ” + error.name + “:” + error.message);
 }

function readData(){
 tizen.widgetservice.getWidgets(function(widgets)
 {
  widgets.forEach(function(widget){
   if(widget.applicationId == “s29U0dfg8I.WidgetSampleHost”){
    widget.getInstances(
    function(instances){
          instances.forEach(function(instance) {
        try {
          instance.getContent(contentSuccessCb, contentErrorCb);
        } catch (error) {
          alert(“Error: ” + error.message);
        }
        });
    }
    , function(error){alert(“error while getting the instance: “+error);});
   }
  });
 }, function(error)
 {
    alert(“Error: ” + error.message);
 });
}
function writeData(){
 tizen.widgetservice.getWidgets(function(widgets)
 {
  widgets.forEach(function(widget){
   if(widget.applicationId == “s29U0dfg8I.WidgetSampleHost”){
    widget.getInstances(
    function(instances){
          instances.forEach(function(instance) {
            var data = {
          data1 : ‘test1’,
          data2 : ‘test2’
         };
        
         try {
           instance.sendContent(data, true);
           alert(“Data has been successfully sent”);
         } catch (error) {
           alert(“Error: ” + error.message);
         }
        });
    }
    , function(error){alert(“error while getting the instance: “+error);});
   }
  });
 }, function(error)
 {
    alert(“Error: ” + error.message);
 });
}
Written by