Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 178
Registered: ‎03-10-2011
My Device: Not Specified
Accepted Solution

BB10 WebWorks: How to invoke SMS app with pre-filled content and without phone number?

[ Edited ]

Say I want to share some contents via SMS, App can prepare the contents, launch SMS app and users enter recipient's number.

 

Is it possible? BB10 WebWorks invoke API seems to require pre-filling recipient's number.

https://developer.blackberry.com/html5/documentation/text_messages.html

 

Thanks

 

Developer
Posts: 178
Registered: ‎03-10-2011
My Device: Not Specified

Re: BB10 WebWorks: How to invoke SMS app with pre-filled content and without phone number?

I tried the following method:

 

try {
    blackberry.invoke.invoke({
        target: "sys.pim.text_messaging.composer",
        action: "bb.action.COMPOSE",
        data: ppsEncode({"body":"line1\n\rline2...", "send":"false"})

    },
    function(successEvt) {},
    function(errorEvt) {}
  );
}
catch (e) {
}

 

var ppsEncode = function (obj) {
  var data = '', name, value;
  for (name in obj) {
    data += name + ':';
    value = obj[name];
    if (typeof value === 'string') {
      data += ':' + value;
    }
    else if (typeof value === 'number') {
      data += 'n:' + value;
    }
    else if (typeof value === 'boolean') {
      data += 'b:' + value;
    }
    else if (typeof value === 'object') {
      data += 'json:' + JSON.stringify(value);
    }
    data += '\n';
  }
  return data;
}

 


I am able to launch SMS composer, recipient list is empty, this is great. But content only has one line. How to use line breaks in SMS composer? I tried \n\r too, still got only one line.

 

Thanks

 

Developer
Posts: 178
Registered: ‎03-10-2011
My Device: Not Specified

Re: BB10 WebWorks: How to invoke SMS app with pre-filled content and without phone number?

[ Edited ]

I found alternative way, instead of calling SMS app directly, I can call Shares target picker API, and from there I select SMS or Email or BBM or Facebook or Twitter or LinkedIn, line break work fine, one API call solves all registered social share services.

 

https://developer.blackberry.com/html5/apis/blackberry.invoke.card.html#.invokeTargetPicker

 

try {
  var request = {
    action: 'bb.action.SHARE',
    data: "Line 1" + "\n" +
          "Line 2" + "\n" +
          "Line 3" + "\n",
    mime: 'text/plain',
    target_type: ["CARD"]
  };

 

  blackberry.invoke.card.invokeTargetPicker(
    request,
    "Share via",
    function(successEvt) {},
    function(errorEvt) {}
  );
}
catch (e) {
}