views:

563

answers:

2

I have an application which is built from command line (ANT) using J2ME Polish. As such, this application is defined through a build.xml, not from Blackberry JDE project files.

What I need to do is have this application auto-start. This is easy enough to do once the application has been run for the first time (example). However, this does require the application to be manually run by the user (which I want to avoid).

The JDE provides options which you can check to enable auto-start, and from ANT:

  <cldc runonstartup=="true"...

Will do the trick. The question is, how do I integrate this into a Polish buiild (i.e. into a Polish build.xml which is also building for other platforms)?

Anyone know what the auto-start option in the JDE actually does / what it changes?

A: 

Another polish user :)

Take a look at BB forums the 2nd post. Then using what we know about polish and jad attributes

Add this to your jad section of your build.xml

<jad>
 <attribute  name="RIM-MIDlet-Flags" 
   value="1" 
  if="polish.vendor == BlackBerry" />
</jad>

I haven't tested this but the logic seems to be valid :) Let me know if it works or not.

drubin
That won't (and doesn't) work - already tried it. Polish Blackberry applications are not MIDlets, despite appearances. The Polish build process translates the MIDlet into a Blackberry UIApplication (see http://www.j2mepolish.org/cms/leftsection/documentation/platforms/blackberry.html#blackberry-gui). Setting RIM-MIDlet-Flags only works for MIDlets, so alas the method you describe doesn't work.
KevinD
I spoke too soon - apparently RIM-MIDlet-Flags *does* work not non-MIDlets... I must be doing something wrong. I will give it a shot again and try and debug whats wrong.
KevinD
Great :) let me know if this works. heheSorry forgot to mention you might need to change the number in this case "1" to something else depending on the device/OS I just noticed some versions list 32 as a valid number for autostart.
drubin
Definitely doesn't work. JarToCodFinalizer (part of the 'Polish Blackberry build chain) hard-codes RIM-MIDlet-Flags to '0', which is passed to RAPC. Without the flags being passed to RAPC, the app doesn't get the-autostart attribute.I think I have a fix, however (which requires changing and building J2MEPolish!).
KevinD
Let me know the patch and I will make sure it get comitted :) Been meaning to add losts of stuff to their BB support.
drubin
+1  A: 

So, the way to do this is, unfortunately, to change the J2ME-Polish source! As outlined in this bug report the J2ME Polish build framework (at version 2.1.4) doesn't pass on the RIM-MIDlet-Flags-x JAD attribute to RAPC.

The changes are relatively simple - merely passing on the RIM-MIDlet-Flags-1 value if defined in the JAD, otherwise setting it to zero (as the original 2.1.4 source does).

The diff (from 2.1.4) source:

Index: /enough-polish-build/source/extensions/de/enough/polish/blackberry/JarToCodFinalizer.java
===================================================================
--- /enough-polish-build/source/extensions/de/enough/polish/blackberry/JarToCodFinalizer.java   (revision 315)
+++ /enough-polish-build/source/extensions/de/enough/polish/blackberry/JarToCodFinalizer.java   (revision 316)
@@ -36,6 +36,7 @@
 import java.util.Calendar;
 import java.util.Locale;
 import java.util.Map;
+import java.util.List;
 import java.util.Properties;

 import org.apache.tools.ant.BuildException;
@@ -185,6 +186,13 @@
            }
        }
        File iconFile = null;
+       Map jadProperties;
+       try { 
+           jadProperties = FileUtil.readPropertiesFile( jadFile, ':' );    
+       } catch (Exception e) {
+           e.printStackTrace();
+           throw new BuildException("Unable to read JAD file " + e.toString() );
+       }
        if (mainClassName != null) {
            try {
                /*
@@ -230,12 +238,26 @@
                        "MicroEdition-Configuration: CLDC-1.1",
                        //"MIDlet-1: Demo," + iconUrl + ",",
                        "MIDlet-1: " + env.getVariable("MIDlet-Name") + "," + iconUrl + ",",
-                       //"MIDlet-Icon: " + iconUrl,
-                       "RIM-MIDlet-Flags-1: 0"
+                       //"MIDlet-Icon: " + iconUrl
                };

+               /* Ensure that if RIM-MIDlet-Flags is defined in the JAD, it is
+                * passed on to RAPC to create the COD file.
+                * See https://developer.berlios.de/bugs/?func=detailbug&amp;group_id=1246&amp;bug_id=16901
+                * for details.
+                */
+               ArrayList newEntriesList = new ArrayList(Arrays.asList(newEntries));
+               final String flagsKey = "RIM-MIDlet-Flags-1";
+               String flagString = (String)jadProperties.get(flagsKey);
+               if (flagString == null) {
+                   flagString = "0";
+               }
+               flagString = flagString.trim();
+               System.out.println("JarToCodFinalizer setting " + flagsKey + ": " + flagString);
+               newEntriesList.add(flagsKey+ ": "  + flagString);
+
                File rapcFile = new File( jadFile.getParent(), codName + ".rapc");
-               FileUtil.writeTextFile( rapcFile, newEntries );
+               FileUtil.writeTextFile( rapcFile, newEntriesList );
            } catch ( IOException e ) {
                // this shouldn't happen
                e.printStackTrace();
@@ -367,7 +389,6 @@
            // now rewrite JAD file so that it is ready for OTA download:
            // (first backup JAD file:)
            //FileUtil.copy(jadFile,  new File(jadFile.getParent(), jadFile.getName() + ".bak") );
-           Map jadProperties = FileUtil.readPropertiesFile( jadFile, ':' );    
            Object[] keys = jadProperties.keySet().toArray();
            for (int i = 0; i < keys.length; i++) {
                String key = (String) keys[i];
KevinD
Committed with some changes see polish thread http://www.j2mepolish.org/forum/viewtopic.php?p=3379#3379
drubin