Need help with Javascript in RMS 4.0 Shared Runtime

Hi all,

we are trying to get started with RMS 4.0 Shared Runtime on a Motorola WT41N0 device.

I read the API docs to setup some modules needed for our web app.

The problem is, that none of the javascript code seems to be executed.

E.g. trying to display indicator icons fails via javascript but works via meta tags.

No icons are displayed:

  Rho.Battery.showIcon();

  batteryValues = Rho.Battery.batteryStatus();

  alert("Battery Level is: " + batteryValues['batteryLifePercent']);

Icons are displayed:

<META HTTP-Equiv="Battery"    Content="Left:260; Top:2; Color:#000000; Layout:Left; IconPosition:Right; GraphPosition:Top; Visibility:Visible">

<META HTTP-Equiv="Signal"     Content="Left:2; Top:2; Color:#000000; Layout:Right; IconPosition:Left; GraphPosition:Top; Visibility:Visible">

<META HTTP-Equiv="KeyState"   Content="Left:155; Top:2; Visibility:Visible">

No matter what I try, it does not work. Just as KeyState and KeyCapture.

Just as I add the Rho object to the source none of the javascript is executed (tested with e.g. alerts).

Config.xml (extract)

      <NPAPI>

        <NPAPIDirectory value="file://%INSTALLDIR%\NPAPI\"/>

        <Preloads>

          <PreloadLegacyGeneric value="1"/>

          <PreloadLegacyODAX    value="1"/>

          <PreloadLegacyNoSIP   value="1"/>

          <PreloadLegacyAirBeam value="1"/>

          <PreloadLegacyAPD     value="1"/>

          <PreloadJSObjects     value="1"/>

        </Preloads>

      </NPAPI>

     

      <Preloads>

        <Preload value="Scanner"/>

        <Preload value="Hourglass"/>

        <Preload value="KeyCapture"/>

        <Preload value="SIP"/>

        <Preload value="ScreenOrientation"/>

      </Preloads>

Any advice?

rgds

Sebastian

Anonymous (not verified)
I tested the code you

I tested the code you provided and was getting some errors, for missing parameters etc. I wrote-up a sample page that should load at least the battery portion correctly through JS.

This looks to be either a documentation issue or an incorrect API implementation, as the code samples @ Rhomobile | Battery show no parameters for the showIcon() and batteryStatus() methods; however, if I implemented the methods as in the samples it wouldn't work until I added at least 1 parameter. More testing to be done, tested w/ MC3190 WM6.5.

<HTML>

<HEAD>

<script type="text/javascript" charset="utf-8" src="PATH TO MY rhoapi-modules.js"></script>

<script type="text/javascript">

   function finLoad() {

      Rho.Battery.showIcon({color:'#0000FF',layout:'up'});

      Rho.Battery.batteryStatus({}, display);

      //alert("Battery level is " + batteryValues['batteryLifePercent']);

   }

  function display(params){

    alert("Battery level is " + params['batteryLifePercent']);

  }

</script>

</HEAD>

   <BODY>

      <div id="htmDiv">

      <p>Hey!</p><p>Hey!</p><p>Hey!</p><button onclick="finLoad()">Battery Status</button>

      </div>

   </BODY>

</HTML>

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sebastian Vajsman
Hi Derek,even this does NOT

Hi Derek,

even this does NOT work... I'm freaking out!

<html>

<head>

<script src="/public/api/rhoapi-modules.js" type="text/javascript"></script>

<script type="text/javascript">

  function bestFunctionEver(){

  Rho.Battery.batteryStatus({}, display);

  }

  function display(batteryValues){

  alert("Battery Level is: " + batteryValues['batteryLifePercent']);

  }

</script>

</head>

<body>

  <div>

        <a href="#" onClick="JavaScript:bestFunctionEver();">Hit Me!</a>

    </div>

</body>

</html>

Maybe it is a WT41N0 or WIN CE 7 specific issue.

I'll try testing on a MC3190/CE6 device later.

Regards

Sebastian

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
I have the same issue in

I have the same issue in getting any JS to work - would someone be able to post a simple working example app at the GitHub rho-samples repository ?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Pietro Francesc...
I had it working during beta

I had it working during beta of v4.0 following these steps:

Just tested on Windows Mobile and it worked perfectly:
1. rake update_rho_modules_js[wm]
2. copied file on server
3. relaunched app on ES400
4. Scanning :-)

I think that this can be closed

See notes on github:

https://github.com/rhomobile/rhoelements-issues/issues/17

~Pietro

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


John Michael Vi...
Hi,Have you tried to include

Hi,

Have you tried to include the rhoapi-modules.js in your external web server pages?

You should extract this javascript from Rhostudio, you could follow this instructions

Rhomobile | Using RhoMobile JavaScript API&rsquo;s

This javascript contains the Rhoelements API such as Keystate, etc.

This api allows us to access the device capabilities such as Network API,

by just using javascript in our backend server, Rhomobile called this as Common API,

since they are available both via ruby and javascript.

Let me know if there are still problems, I would be glad to help.


Regards,

Vine

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sebastian Vajsman
Hi Vine,thank you for your

Hi Vine,

thank you for your reply.

As far as I understood the docs, you do not need to do this step using the Shared Runtime on Win CE devices,

because JS modules are injected via NPAPI (see the extracted part  of config.xml).

However I already tried it

The test page I was fighting with is on the device (local):

\Application\RhoElements\HTML\test.html

The JS file is under:

\Application\RhoElements\rho\apps\public\api\

I already tried to address it relatively with:

<script type="text/javascript" charset="utf-8" src="../rho/apps/public/api/rhoapi-modules.js"></script>

But nothing seems to work.

This one worked

<META HTTP-Equiv="KeyCapture" content="KeyValue:0x0D; Dispatch:False; KeyEvent:url('http://www.motorola.com');">

So KeyCapture seems to be preloaded at least.

This only works for the ENTER Key.

The F-Keys do not respond. Not even a simple JS alert...

Regards,

Sebastian

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
The correct path to the a pi

The correct path to the a pi js file is just \public\api

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sebastian Vajsman
I'm a little bit confused

I'm a little bit confused regarding the JS api file and the shared runtime.

In the docs it says, that including the JS file is not necessary, because JS is injected through NPAPI.


  1. <NPAPI> 
  2.         <NPAPIDirectory value="file://%INSTALLDIR%\NPAPI\"/> 
  3.         <Preloads> 
  4.           <PreloadLegacyGeneric value="1"/> 
  5.           <PreloadLegacyODAX    value="1"/> 
  6.           <PreloadLegacyNoSIP   value="1"/> 
  7.           <PreloadLegacyAirBeam value="1"/> 
  8.           <PreloadLegacyAPD     value="1"/> 
  9.           <PreloadJSObjects     value="1"/> 
  10.         </Preloads> 
  11.       </NPAPI>

Anyway if have to include the JS file in the HTML head, why is the path just

\public\api

when my html file lays in

\Application\RhoElements\HTML\

Imho there must be a difference between a native app and the shared runtime regarding the inclusion of the js api file.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
Make sure you put the rhoapi

Make sure you put the rhoapi-modules.js before JQM

<script src="/public/api/rhoapi-modules.js" type="text/javascript"></script>

<script src="/public/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>




Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Sebastian Vajsman
Ok I got it... at least Hello

Ok I got it... at least Hello World...

<html>

<head>

<META HTTP-Equiv="KeyState" Content="Left:155; Top:2; Visibility:Visible">

<script src="../rho/apps/public/api/rhoapi-modules.js" type="text/javascript"></script>

<script type="text/javascript">

  function test(){

  Rho.Battery.batteryStatus({}, display);

  }

  function display(batteryValues){

  alert("Battery Level is: " + batteryValues['batteryLifePercent']);

  }

</script>

</head>

<body>

    <div>

  <a href="#" onclick="Javascript:test();">hit me hard!</a>

  </div>

</body>

</html>

This works.

Downloaded the official RMS 4.0 from Motorola Website and redeployed RE on the mobile device.

Then i got the following log message:

I 01/01/2009 00:08:18:000 00a6018e RhoWKBrowserEngine.cpp: 558| JS Log: file:///Program%20Files/RhoElements/HTML/test.htm, line 7: ReferenceError: Can't find variable: Rho

Added this line to test.htm

<script src="../rho/apps/public/api/rhoapi-modules.js" type="text/javascript"></script>

And it works... I get the JS alert popup.

BUT... I get it all 5 seconds (as the battery refresh rate is set to 5000ms)

Why is the function triggered all 5000ms automatically?

In this case I would have thought it is executed only on click of the link.

How can I achieve this behaviour?

Regards

Sebastian

Happy anyways for reaching Hello World milestone

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hello Sebastian,

Hello Sebastian,

BUT... I get it all 5 seconds (as the battery refresh rate is set to 5000ms)

Why is the function triggered all 5000ms automatically?

In this case I would have thought it is executed only on click of the link.

How can I achieve this behaviour?

The Battery module was designed to continuously notify the web page of the battery level, this way the page can:

  1. Use this information for it's own custom Battery icon/status report
  2. Do actions at specific levels (for example, send all unsaved data to the server when the battery goes below 10%)


But of course, there will be times where you may want a one off reading just like what you are wanting. To do this, you need to stop the battery updates once you have received one event. This can be done with the JavaScript method:

Rho.Battery.stopBatteryStatus();

To fit this into your program, add it to the "display(...)" function:

<html>

<head>

  <META HTTP-Equiv="KeyState" Content="Left:155; Top:2; Visibility:Visible">

  <script src="../rho/apps/public/api/rhoapi-modules.js" type="text/javascript"></script>

  <script type="text/javascript">

    function test(){

      Rho.Battery.batteryStatus({}, display);

    }

    function display(batteryValues){

      alert("Battery Level is: " + batteryValues['batteryLifePercent']);

      Rho.Battery.stopBatteryStatus(); //Add this line

    }

  </script>

</head>

<body>

  <div>

    <a href="#" onclick="Javascript:test();">hit me hard!</a>

  </div>

<body>

</html>

Best regards,

Ben

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Sebastian Vajsman
Nice! Thank you Ben.I see I

Nice! Thank you Ben.

I see I have to work through the API docs now that it seems to work.

Thanks everybody though for your support!

Edit: Note for RE devs: NPAPI injection still seems not to work properly.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


John Michael Vi...
Glad you have sort it out

Glad you have sort it out.

META tags are already deprecated. So better  use the Javascript API.

Remember the good thing in RMS 4.0, we don't need to deploy our webapp in

the apk itself, all web pages our external and device capabilities are accessible via javascript!

Unlike other competitors such as phonegap, this isn't possible, but in RMS 4.0 it is,

its just cool!

Regards,

Vine

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments