Widget Javascript Extension: reminder

Hi guys,.

I am currently developing widgets using Javascript Extension also.

I am facing a problem.

In my class that extends from ScriptableFunction, how do I manage an object passed to call methods as arguments and representing a "pointer" to the javascript function to use as the asynchronous callback?

How can I call it?

Thank you very much.

Concerning

Scarex

Hi Scarex,

It's a really great question.  You can execute JavaScript in Java by using the executedScript() method which accepts a string as a parameter.  Rather than pass a pointer to a JavaScript method, you can provide the name of the function as well as all the parameters.

Here's an example of how you could spend two whole arguments to a ScriptableFunction and make a call to a JavaScript function named 'add', passing the following values:

ScriptableFunction _myFunc = new ScriptableFunction()
{
   public Object invoke(Object obj, Object[] args) throws Exception
   {
      if (args.length == 2) {
         int param1 = ((Integer)args[0]).intValue();
         int param2 = ((Integer)args[1]).intValue();
         _browserField.getScriptEngine().executeScript("add(" + param1 + ", " + param2 + ")", null);
      }
      return UNDEFINED;
   }
};

Here's what could resemble the method add() method JavaScript, defined in the BlackBerry Widget application web content:


I hope this helps.

Best wishes

Adam

Tags: BlackBerry Developers

Similar Questions

  • call a javascript extension

    Hey

    I am very new to Blackberry/Java development if any help would be great.

    Using the tutorial on how to create blackberry javascript extensions that I wrote a very simple extension that will download a file from you.  Everything seems fine, I can export the JAR but I get the following in eclipse warning:

    Description Resource Path Location Type
    Signing Required: RIM Blackberry Apps API (0x52424200): Import uses protected Class net.rim.device.api.web.WidgetConfig ByteReaderExtension.java /TribalWorksByteReader-OS6/src/tribal line 5 BlackBerry Protected API
    

    When I try to use the extension to javascript in my application webworks, nothing happens.  Simply, it stops and does not receive from past the line, where I make my call.

    alert("before extension call");
    tribal.download.downloadFile(remoteFile, localFile);
    alert("after extension call");
    

    In the emulator, I get the first alert, but not the second.  I'm also a few calls from Dialog.alert in my extensions javascript that ever fire.  Kind of I'm stuck at this stage since there is no errors so I don't really know where to start.

    Someone knows something similar or know how I can fix this?

    Packer widget 1.5

    OS: 6.0.0.337

    Device: 9800

    I am also to build my javascript extension nuer Blackberry JRE 6.0.0

    Edit: I'm also compiling the application with bbwp.exe

    Thank you!

    Chris

    I thought about it.

    I used a file struggle to update the index.zip and compile it with bbwp.exe.

    I forgot to add the ext for the zip folder.

  • How to get the Javascript Extension written for Tablet Playbook/submit to App World

    WebWork SDK "TABLETS" documentation:

    https://developer.BlackBerry.com/HTML5/documentation/ww_release_notes/bb_webworks_sdk_tablets_rn_2.2...

    It shows that we can

    "use the JavaScript extensions-

    You can create JavaScript extensions to enhance your applications by adding them to archive the application before compiling the source of the application. You can modify and distribute these extensions. "

    However, even I can successfully test the extension on my local playbook in the folder "\BlackBerry WebWorks SDK for Tablet 2.2.0.5\bbwp\ext", I can't find doc showing what to do during the presentation of the app on the app store with my extension. WeBWorK for smartphone seems obvious because it uses the java & jar, but just can not find information about the expansion on tablet...

    The extension is integrated within your compiled cod or bar. you have nothing to do rather than download the bar or COD.

  • What controls available for javascript extensions?

    Hello

    I would like to know what controls are available for javascript extensions. I mean, that control can I put on a pdf page or nearby? I read the documentation and I hope I'm wrong, because I've heard they can be put in a dialog box. Thanks in advance

    Controls that you can place on a page that can trigger the code are different types of form fields. You can also create custom for a document toolbar buttons.

  • GUI or Console output javascript extension

    While working at webworks I have user "alert" for the values of the variables and to control the flow of control.

    Now I started to write javascript in java extension

    but whenever I tried Dialog.alert ("message"); the extension projects working

    is it like the extension of javascript may not show any output GUI?

    If that's how I can see in the console?

    How can I check the values of variables?

    or whenever I click on a button I want to see that the id of the function being called correctly so I usually put alert()

    is there something that I can put inside the java classes or can print the output on console?

    He got so called DIalog.alert I have to do

    class Recording extends Thread{
    
        public void run(){
            UiApplication.getUiApplication().invokeAndWait(new Runnable() {
                    public void run() {
                       Dialog.inform("Thread started inside java and this is inside run");
                    }
                 });
        }
    }
    
  • Threading in extension of blackberry widget

    Hello, I am new to blackberry widget development. I created an extension that allows me to get a precise gps location, however my application hangs while he does this, how can I implement threading in my extension.

    I searched for days and has been unable to find anything. Any help I appreciated

    What platform are you on?  BB OS 5.0 or 6.0?  There is a difference in threading between the two.

    The Widget JavaScript Extensions are on the thread to dispatch event application on 6.0, but not on 5.0.  In both cases, however, you must configure your GPS receiver on a separate extension thread.  It is done the same thing, as in any other Java environment, using Thread or Runnable classes.

    public class MyExtensionFunction extends ScriptableFunction {    public Object invoke(Object obj, Object[] oargs) throws Exception {        // Run this on a background thread so that JavaScript can continue on        Thread thread = new Thread(new Runnable() {            public void run() {                // set up GPS listener here            }        });        thread.start();    }}
    
  • Initialize the object of BrowserField of Extension JS

    Hello

    I found a post very useful for my scenario to

    http://supportforums.BlackBerry.com/T5/Web-development/widget-JavaScript-extension-callback/m-p/4725...

    According to Adam's response, we can make the reminder in JS extension with piece of code below,

    ScriptableFunction _myFunc = new ScriptableFunction()
    {
       public Object invoke(Object obj, Object[] args) throws Exception
       {
          if (args.length == 2) {
             int param1 = ((Integer)args[0]).intValue();
             int param2 = ((Integer)args[1]).intValue();
             _browserField.getScriptEngine().executeScript("add(" + param1 + ", " + param2 + ")", null);
          }
          return UNDEFINED;
       }
    };
    

    Can someone tell me how we can initialize the object '_browserField' in Java, or is - it be passed as an argument to the call of the JS Extension.

    Thanks in advance,

    Ziya.

    Hi Ziya,

    There is an even easier way to make a reminder in your javascript.  What you can do, it is something like the following pseudocode:

    ScriptableFunction _myFunc = new ScriptableFunction()
    {
       public Object invoke(Object obj, Object[] args) throws Exception
       {
          if (args.length == 2) {
             int param1 = ((Integer)args[0]).intValue();
             int param2 = ((Integer)args[1]).intValue();
             ScriptableFunction add = (ScriptableFunction)args[3];
             add.invoke(add, [param1, param2]);
          }
          return UNDEFINED;
       }
    };
    

    Basically you can actually spend in a JavaScript function as a parameter for a reminder.  You can then grasp the handle to the ScriptableFunction and then call its invoke just as your own ScriptableFunction is called.

    It is much cleaner and allows you to really take a pointer to the instance of the Add function that you are willing to call.

  • How to use the persistent storage

    Hello... Can we use persistent in blackberry webworks storage... I don't want to use SQLite... Any suggestions...

    joygupta wrote:
    Thanks for your reply... you can give a sample of the same...

    Now, things you need to know:

    -creation of Javascript Extension in the development of Blackberry Webworks.

    -How to set up a persistent Java development storage

    You can do a search on Google for more include some documentation and samples.

    As a sample of a documentation:

    http://www.Scribd.com/doc/39084892/lab-building-a-BlackBerry-widget-JavaScript-extension

    or an example of project: http://na.blackberry.com/eng/developers/devbetasoftware/Lab_Widget_Extension.zip

  • Cannot compile BB Widget with JavaScript Custom Extension

    Hello:

    I have came across the entire video creating a Javascript Extension customized for BB Widgets and made my own. I made some functions available and named my main package as 'rgpackage' and this is where all of my classes.

    After that, I just exported to a JAD/JAR file (just like the video says).

    Open Web plug-ins, BlackBerry (v2.0.0.201003191451 - 33) and a new project of Widget of BB.

    A new ext folder appeared and I dragged my JAR/JAD file in this folder.

    Went to the file config.xml by default BB Widget Config Editor and added functionality. Mine appeared in the list, so I double clicked it.

    Everything is fine now. Add the code to my main index.html file to test my extension.

    When press the 'Run' button, my widget has started to compile (and also the extension) and this message keeps appearing (and I can't get rid of it... at least I do not know how and what could happen):

    [INFO]              Compilation of widget
    C:\Users\Andy\AppData\Local\Temp\widgetGen.3461070221272448531372.tmp\blackberry\web\widget\autogen\WidgetConfigAutoGen.Java:27: package rgpackage does not exist
    _widgetExtensions.addElement (rgpackage again. RGPhotoTakerExtension());

    Please help as I cannot move with the development because of this error (weird?).

    Thank you in advance.

    Andy

    Trying to get this to work finally found the problem.

    Anyone for reference:

    During the export of JAR file, the 'resources and Export Java source files' option should be selected instead of "Export generated resources and class files". In my Eclipse, the last of them has been selected by default.

    Unfortunately, the video tutorial is not clear on this point. Anyway, you can see in the video that the correct option is selected, but because it is not mentioned, it can be confusing as it dawned on me.

    But now, everything works as expected. Finally!

    I thank everyone.

    Andy

  • Problem in javascript for OS 6 API extension

    I wrote an application for smartphone using Webworks with javascript extension. I created a JavaScript library using barcode API of OS 6.0. Ideally WebWorks support OS 5.0 and above so that any javascript extension written using OS6.0 API should work. I followed the direction:

    http://docs.BlackBerry.com/en/developers/subcategories/?usertype=21&category=BlackBerry+WebWorks+for...

    I created a library for barcode scanner added this library in my webworks app and try to compile. It gives me error all the APIs I took the OS 6.0. as

    ********************************************************************************

    DemoProject BUILDING

    cmd.exe /c bbwp D:\abc\projects\webworks\workspace\DemoProject\build\DemoProject.zip/o D:\Manish_Ranjan\projects\webworks\workspace\DemoProject\build

    [INFO]                  Parsing of the command line options

    [INFO]                  Bbwp.properties analysis

    [INFO]                  Validation of archive application

    [INFO]                  The analysis of config.xml

    [INFO]                  The application of filling source

    [INFO]                  Compilation of application BlackBerry WebWorks

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:8: package net.rim.device.api.barcodelib does not exist

    Import net.rim.device.api.barcodelib.BarcodeDecoder;

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:9: package net.rim.device.api.barcodelib does not exist

    Import net.rim.device.api.barcodelib.BarcodeDecoderListener;

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:10: package net.rim.device.api.barcodelib does not exist

    Import net.rim.device.api.barcodelib.BarcodeScanner;

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:18: package com.google.zxing does not exist

    import com.google.zxing.BarcodeFormat;

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:19: package com.google.zxing does not exist

    import com.google.zxing.DecodeHintType;

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:59: cannot find symbol

    symbol: BarcodeScanner class

    Location: class bar code. BarcodeFunction.ViewFinderScreen

    private BarcodeScanner _scanner;

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:70: cannot find symbol

    symbol: variable BarcodeFormat

    Location: class bar code. BarcodeFunction.ViewFinderScreen

    formats.addElement (BarcodeFormat.QR_CODE);

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:72: cannot find symbol

    symbol: variable DecodeHintType

    Location: class bar code. BarcodeFunction.ViewFinderScreen

    hints.put (DecodeHintType.POSSIBLE_FORMATS, formats);

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:75: cannot find symbol

    symbol: BarcodeDecoder, class

    Location: class bar code. BarcodeFunction.ViewFinderScreen

    Decoder BarcodeDecoder = new BarcodeDecoder (hints);

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:75: cannot find symbol

    symbol: BarcodeDecoder, class

    Location: class bar code. BarcodeFunction.ViewFinderScreen

    Decoder BarcodeDecoder = new BarcodeDecoder (hints);

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:80: cannot find symbol

    symbol: BarcodeDecoderListener, class

    Location: class bar code. BarcodeFunction.ViewFinderScreen

    BarcodeDecoderListener decoderListener = new BarcodeDecoderListener() {}

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:80: cannot find symbol

    symbol: BarcodeDecoderListener, class

    Location: class bar code. BarcodeFunction.ViewFinderScreen

    BarcodeDecoderListener decoderListener = new BarcodeDecoderListener() {}

    ^

    C:\Users\abc\AppData\Local\Temp\widgetGen.1978923101309259162010.tmp\extension\barcode\BarcodeFunction.Java:92: cannot find symbol

    symbol: BarcodeScanner class

    Location: class bar code. BarcodeFunction.ViewFinderScreen

    _scanner = new BarcodeScanner (decoder, decoderListener);

    In my extension javascript library.xml file I defined the platform tag.

    Although if I write any extension of javascript for the API available in OS 5.0 that works very well. Is there something more I need to follow for OS 6.0 API-specific javascript extension?

    Thank you

    Manish

    The question that you are running is the WebWorks SDK provided with the library net_rim_api.jar for BB5.  This means that the BB6 API are not in this library link to.

    We are looking to add a new net_rim_api.jar to the SDK so that people can take advantage of the API of BB6.  However, do not know if you are using a BB6 API your app does not work on BB5.  When the application starts, it will get a link error because the API expected is not present.

    You can make your extension work on BB6 by downloading the Java SDK and copy the net_rim_api.jar file and place it in your SDK WebWorks... I believe in the SDK WebWorks is in your directory "lib".

  • Questions about the Extension of JavaScript and SQLite

    Hi all

    I worked with some my colleague on projects related to WebWorks applications, but there are technical issues that our developers want to know and seek professional advice.

    (1) extension JavaScript & PlayBook

    According to the literature, we know that BlackBerry WebWorks Application have the ability to integrate with data, characteristics and features of the development environment Java® underlying as well as the native phone smart BlackBerry® using special JavaScript® (Extension of JavaScript) objects. So, we should be able to create® for Java (JAR) libraries and program the WebWorks app for BlackBerry Java API to call in libraries. Now, we know that BlackBerry® PlayBook provide a SDK WebWorks (Beta) for us to develop apps for PlayBook WebWorks, also means that in the environment of the PlayBook we can also use the JavaScript Extension trick to call the Java API of BlackBerry?

    (2) SQLite on HTML5

    HTML5 standard offer of SQLite for us to store data in a SQLite database format. But the SQLite file seems limited only to be used in the Application of WebWorks. I wonder if there are ways we can read these file to another application (Application Java or other applications WebWorks) SQLite?

    In fact, what I want to know is the possibility of having a WebWorks Application capable of handling a SQLite file that is received from the server side on-the-fly, and then return the entire SQLite file to the server.

    It would be appreciated if some of you can give some tips about this, thank you.

    Wowzzz

    lasterra is right about these two points...

    We have not yet published the details on creating extensions in the AIR for WebWorks on PlayBook. We are currently working to finalize the open source on the WebWorks for PlayBook SDK so that we can download on github.  The complete source code for the platform will be available on github so that you can see what's going on under the hood.

    Creating extensions in the AIR for WebWorks is very different from Java. We started to use a new architecture that should be able to provide the URI and proceedings access to APIs and placing more procedural API code in JavaScript itself vs. the ScriptableObject Java code existing today.

    This new architecture will be a foretaste of the platform architecture WebWorks to proceed.

    It welcomes more details about creating extensions in the AIR... but currently the API underlying main platform on the BlackBerry PlayBook is AIR and the functionality of an extension will be limited to what is possible on the AIR platform and its extensions.

    In the development of the PlayBook options evolve, so too will be the architecture of the platform WebWorks... I can't really say much more than this now

  • Check out native BB Web App and Javascript

    Hey everybody,

    I'm working on Blackberry to develop a web application and I had to transfer some of the tasks to a native hook.

    Now expand the native javascript hook to use seems fine, the biggest problem Im having is that I can't connect to a some paper (i.e. within the web application can I print to a kind of diary? From my native code I cant seem to System.out.print to the console as Eclipse sees the project as a web app and seems just to set the console to another point of view.

    Can anyone give me any suggestions or correct me on how to get some kind of output?

    See you soon,.

    Matt

    I created a JavaScript Extension (native code) that writes to the BlackBerry event log.  I also use it as a feature in my Widget application and override console.log (and do invoke the native Logger).

    The good thing about the event log, is that it is too on the device.  In the current state of debugging by using the available tools, this feature helped me tremendously.

    Use the Source.  Or better, use phonegap and get you it for free.

    The showeventlog application is the best way to view the log of events on the device/Simulator.

  • Widgets on pre 5.0 devices

    At a high level, what are the OS 5.0 required features that are not available for devices running OS< 5.0? ="" in="" other="" words,="" is="" there="" going="" to="" be="" any="" way="" to="" run="" widgets="" on="" older="">

    I like the new method of development of widget, but it will be a moment very, very long time before of OS 5.0 will be widely used.  Once the new OS 5.0 is released for older devices, it takes a long time for carriers to make them accessible, and there are still like for users and companies to actually upgrade the devices more ancient (if any).

    Fred

    Hi Fred,.

    There are two main components that are on 5.0 that allow widgets.

    (1) BrowserField2 that allows custom JavaScript extensions

    (2) BlackBerry Widget JavaScript API that are part of the operating system

    So without these two items on the older operating systems, widgets do not work.

    Updating and dissemination of the new operating system takes time.  It is a technology which is something that we are eager to build and also provide a new way for the development on new smartphones as they come out.

  • invoking the java object in a widget

    Hello

    is it possible to invoke java objects in a widget or only java application complete?

    for example, I tried:

    var args = new blackberry.invoke.JavaArguments('net.rim.device.api.system.Alert.startVibrate(25500);');
    blackberry.invoke.invoke(blackberry.invoke.APP_JAVA, args);
    

    but his does not work is there a way to do it?

    bert2002

    Hi bert2002,

    You can call a "Java Application" by using the API that you have demonstrated to invoke.  But not a Java API.

    You can create a JavaScript Extension that will wrap any Java API so that you can use in your widget.  A video on how to make can be found here:

    http://www.BlackBerry.com/DevMediaLibrary/view.do?name=WritingJavaScriptExtensions

    As well as a lab here:

    http://NA.BlackBerry.com/eng/developers/devbetasoftware/Lab_Widget_Extension.zip

  • Extension of 10 BB WebWorks

    Is there a documentation or examples on how to create custom JavaScript extensions supported by the native code for the new SDK of WebWorks BB 10? My understanding is that extensions for BB 10 WebWorks will be written in native C/C++ code. However, all the implemented API looking at existing WebWorks BB 10 SDK, contain only JavaScript code. It looks like the API currently implemented to provide a JavaScript interface to interact with a server running on the phone that handles native-code extensions. I don't see native code for extensions in the current SDK, so I guess that these implementations are integrated into BB 10.

    I guess that a custom extensions JavaScript should somehow register its implementation of native code with this same server but it is not clear to me how this is done.  Is there any documentation or examples of this yet?

    You're right: BB10, there will be a JavaScript interface that calls down to native code.  However we have not this architecture in place for the 3rd party developers yet, but its definitely coming.

    Brace yourself for updates, we will make sure to communicate best practices and guidelines for BB10 + WebWorks development of extensions with the community once it is ready.

Maybe you are looking for