语言

Menu
Sites
Language
Error when create ApplicationControlData

When I run below code

        try {
            var appControlData = new tizen.ApplicationControlData('text', [text]);
        } catch(ex) {
            console.log(ex.message);
            return;
        }
        var appControl = new tizen.ApplicationControl(
            'http://tizen.org/appcontrol/operation/compose',
            null,
            "text/html",
            null,
            [appControlData]
        );

        var callbacks = {
            onsuccess: function() { console.log('Sending SMS succeeded')},
            onfailure: function() {console.log('Sending SMS failed') }
        };

        console.log("Launch service");

        tizen.application.launchAppControl(
            appControl,
            "tizen.messages",
            function() {console.log("launch application control succeed"); },
            function(e) {console.log('launch appControl failed. Reason: ' + e.name)},
            callbacks
        );

On the second line: 

    var appControlData = new tizen.ApplicationControlData('text', [text]);

I get an error saying "The type of an object is incompatible with the expected type of the parameter associated to the object.", how come this error happens? BTW, text is of string type

响应

9 回复
Raghu Kona

Hi,

In ApplicationControlData, the value field takes array of strings as argument.

 [Constructor(DOMString key, DOMString[] value)]
  interface ApplicationControlData {

    attribute DOMString key;

    attribute DOMString[] value;

  };

You can try modifying the code as

  var myText = ["text1","text2","text3"];

  var appControlData;
    
    try { appControlData = new tizen.ApplicationControlData('text', myText); }

 

Regards,

Raghu Kona

Imgen Tata

Hi, you can see from my code, it's already a string array

Imgen Tata

Although it's a single string element array

Alexander AVSukhov

Hello,

Make sure that the variable "text" is string.

I have tested this code on tizen  device with 2.2.0 and it works fine.

Imgen Tata

You tested on device? I have only tested on Web Simulator of SDK 2.2.1 and it throws error. I'll try to test on Tizen SDK 2.2 emulator to see the result. 

Marco Buettner

on simulator you can not use all tizen APIs... appControl starts another app and that can not be simulate... So it will better to test it on the emulator.

Imgen Tata

You are right, on the emulator, it is working correctly. Thanks for the tip.

Andrew Gudz

Try this:

var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/compose", "sms:" + "423532452345");
tizen.application.launchAppControl(appControl, "tizen.messages", function() {
    console.log("messageToContact: launch appControl succeeded");
}, function() {
    console.log("messageToContact: launch appControl failed. Reason: " + e.name);
});

 

Imgen Tata

Hi, I need to set text of the message though, and I don't know the recipient of the message, so probably this won't work