Showing posts with label J2ME. Show all posts
Showing posts with label J2ME. Show all posts

Friday, October 29, 2010

Configuring NetBeans for BlackBerry development







  • Install BB JDK.
  • Copy following to a file and make necessary changes. 
    <?xml version='1.0'?>
    <!DOCTYPE platform PUBLIC '-//NetBeans//DTD J2ME PlatformDefinition 1.0//EN' 
              'http://www.netbeans.org/dtds/j2me-platformdefinition-1_0.dtd'>
    <platform name="BlackBerry_JDE_421" 
              home="C:\Program Files\Research In Motion\BlackBerry JDE 4.2.1" 
              type="CUSTOM" 
              displayname="BlackBerry JDE 421" 
              srcpath="" 
              docpath="${platform.home}/docs/api," 
              preverifycmd="&quot;{platformhome}{/}bin{/}preverify&quot; 
                            {classpath|-classpath &quot;{classpath}&quot;} 
                            -d &quot;{destdir}&quot; &quot;{srcdir}&quot;" 
              runcmd="cmd /C &quot;cd /D {platformhome}{/}simulator&amp;{device}&quot;" 
              debugcmd="cmd /C &quot;cd /D {platformhome}{/}bin&amp;jdwp&quot;">
        <device name="8800" description="8800">
            <optional name="JSR75" version="1.0" 
                      displayname="File Connection and PIM Optional Packages" 
                      classpath="${platform.home}/lib/net_rim_api.jar" 
                      dependencies="" default="true"/>
            <optional name="MMAPI" version="1.0" 
                      displayname="Mobile Media API" 
                      classpath="${platform.home}/lib/net_rim_api.jar" 
                      dependencies="" default="true"/>
            <configuration name="CLDC" version="1.1" 
                           displayname="Connected Limited Device Configuration" 
                           classpath="${platform.home}/lib/net_rim_api.jar" 
                           dependencies="" default="true"/>
            <optional name="OBEX" version="1.0" 
                      displayname="Object Exchange APIs" 
                      classpath="${platform.home}/lib/net_rim_api.jar" 
                      dependencies="" default="true"/>
            <optional name="JSR82" version="1.0" 
                      displayname="Java APIs for Bluetooth Wireless Technology" 
                      classpath="${platform.home}/lib/net_rim_api.jar" 
                      dependencies="" default="true"/>
            <optional name="WMA" version="1.1" 
                      displayname="Wireless Messaging API" 
                      classpath="${platform.home}/lib/net_rim_api.jar" 
                      dependencies="" default="true"/>
            <optional name="JSR179" version="1.0" 
                      displayname="Location Based APIs" 
                      classpath="${platform.home}/lib/net_rim_api.jar" 
                      dependencies="" default="true"/>
            <optional name="JSR177" version="1.0" 
                      displayname="Security and Trust Services APIs" 
                      classpath="${platform.home}/lib/net_rim_api.jar" 
                      dependencies="" default="true"/>
            <profile name="MIDP" version="2.0" 
                     displayname="Mobile Information Device Profile" 
                     classpath="${platform.home}/lib/net_rim_api.jar" 
                     dependencies="" default="true"/>
        </device>
    </platform>
  • Save it under - C:\Documents and Settings:
    .netbeans\6.x\config\Services\Platforms\org-netbeans-api-java-Platform 
    as  BlackBerry_JDE_421.xml.
  • Restart NetBeans. 
  • Open a Mobile project and add following to build.xml (just above </project> tag)

    <target name="do-preprocess">
            <fail unless="libs.ant-contrib.classpath">
         Classpath to Ant Contrib library (libs.ant-contrib.classpath property) is not set.
            </fail>
            <taskdef resource="net/sf/antcontrib/antlib.xml">
                <classpath>
                    <pathelement path="${libs.ant-contrib.classpath}">
                </pathelement></classpath>
            </taskdef>
            <available file="${platform.home}/bin/rapc.exe" property="do.rapc">
            <if>
                <isset property="do.rapc">
                <then>
                    <property name="jpda.port" value="8000">
                    <path id="antlib.classpath">
                        <fileset dir="${user.dir}/mobility8/modules/ext/" includes="ant-contrib-1.0b3.jar">
                    </fileset></path>
                    <mkdir dir="${dist.dir}">
                    <path id="src-files">
                        <fileset dir="${src.dir}" includes="**/*.*">
                    </fileset></path>
                    <property name="srcs" value="${toString:src-files}">
                    <for delimiter=";" list="${srcs}" param="file" trim="true">
                        <sequential>
                            <echo append="true" file="${src.dir}/${name}_build.files" message="@{file}${line.separator}">
                        </echo></sequential>
                    </for>
                    <touch file="${dist.dir}/${dist.jar}">
                    <nb-overrideproperty name="buildsystem.baton" value="${preprocessed.dir}">
                </nb-overrideproperty></touch></property></mkdir></property></then>
                <else>
                    <nb-overrideproperty name="buildsystem.baton" value="${src.dir}">
                    <antcall target="${name}-impl.do-preprocess">
                </antcall></nb-overrideproperty></else>
            </isset></if>
        </available></target>
        <target name="do-compile">
            <if>
                <isset property="do.rapc">
                <then>
                    <antcall target="create-jad">
                    <antcall target="update-jad">
                    <copy file="${dist.dir}/${dist.jad}" todir="${src.dir}">
                    <exec dir="${src.dir}" executable="${platform.home}/bin/rapc.exe" failonerror="true">
                        <arg value="-quiet">
                        <arg value="import=${platform.bootclasspath};${libs.classpath}">
                        <arg value="codename=${name}">
                        <arg value="-midlet">
                        <arg value="jad=${dist.jad}">
                        <arg value="@${name}_build.files">
                    </arg></arg></arg></arg></arg></arg></exec>
                    <delete file="${basedir}/${src.dir}/${name}_build.files">
                    <copy file="${name}.alx" todir="${dist.dir}">
                    <nb-overrideproperty name="buildsystem.baton" value="${build.classes.dir}">
                </nb-overrideproperty></copy></delete></copy></antcall></antcall></then>
                <else>
                    <nb-overrideproperty name="buildsystem.baton" value="${preprocessed.dir}">
                    <antcall target="${name}-impl.do-compile">
                </antcall></nb-overrideproperty></else>
            </isset></if>
        </target>
        <target name="pre-obfuscate">
            <nb-overrideproperty name="buildsystem.baton" value="${build.classes.dir}">
        </nb-overrideproperty></target>
        <target if="do.rapc" name="post-jar">
            <move todir="${dist.dir}">
                <fileset dir="${src.dir}">
                    <include name="**/${name}*.*">
                </include></fileset>
            </move>
            <copy todir="${platform.home}/simulator" verbose="true">
                <fileset dir="${dist.dir}">
                    <include name="**/${name}*.*">
                </include></fileset>
            </copy>
        </target>
        <target name="post-clean">
            <delete failonerror="false" includeemptydirs="true">
                <fileset dir="${platform.home}/simulator">
                    <include name="**/${name}*.*">
                </include></fileset>
                <fileset dir="${dist.dir}">
                    <include name="**/*.*">
                </include></fileset>
                <fileset dir="${src.dir}">
                    <include name="**/${name}*.*">
                </include></fileset>
            </delete>
        </target>
  • Create a file called [appname].alx in the project level and copy following to it.

    <loader version="1.0">
        <application id="MobileApplication1">
            <name>
               MobileApplication1
            </name>
            <description/>
            <version>
                1.0
            </version>
            <vendor>
            </vendor>
            <copyright>
            </copyright>
            <fileset Java="1.3">
                <directory/>
                <files>
                    MobileApplication1.cod
                </files>
            </fileset>
            <application id="MobileApplication1">
                <name/>
                <description/>
                <version>
                    1.0
                </version>
                <vendor>
                    Sun Microsystems Inc.
                </vendor>
                <copyright>
                    Copyright (c) 2008 Sun Microsystems Inc.
                </copyright>


            </application>
        </application>
    </loader>
  • That's it

  • Share Article : Configuring NetBeans for BlackBerry development
    Share/Save/Bookmark

    Thursday, December 24, 2009

    Motorola System Properties


    Important
    • Some of these system properties may return null as they may not be supported on early devices.
    • Some system properties require the MIDlet to be signed otherwise return null.



    "default.timezone",
    "microedition.timezone",
    "midp_selector_exit",
    "midp_alert_done",
    "midp_command_menu",
    "midp_selector_launch_failed",
    "midp_vertical_scroll",
    "midp_scrollbar_width",
    "midp_screen_background",
    "midp_screen_foreground",
    "midp_screen_linked_color",
    "midp_enhance_create_cropped_image",
    "midp_enhance_flush_game_graphics",
    "midp_game_flush_compatible_wt_wtk",
    "microedition.configuration",
    "microedition.platform",
    "microedition.locale",
    "microedition.encoding",
    "microedition.profiles",
    "microedition.hostname",
    "microedition.jtwi.version",
    "microedition.commports",
    "commports.maxbaudrate",
    "CellID",
    "LocAreaCode",
    "IMSI",
    "IMEI",
    "MSISDN",
    "batterylevel",
    "funlight.product",
    "supports.mixing",
    "supports.audio.capture",
    "supports.video.capture",
    "supports.recording",
    "microedition.media.version",
    "audio.encodings",
    "video.encodings",
    "video.snapshot.encodings",
    "wireless.messaging.sms.smsc",
    "wireless.messaging.mms.mmsc",
    "com.mot.carrier.URL",
    "microedition.io.file.FileConnection.version",
    "file.separator",
    "com.mot.carrier.URL",
    "microedition.m3g.version",
    "com.mot.carrier.URL",
    "device.software.version",
    "device.model",
    "microedition.pim.version",
    "language.direction",
    "location_category_max_length",
    "location_landmark_max_length",
    "MAType",
    "GPRSState",
    "microedition.smartcardslots"


    Following are applicable only latest Mobile Linux platform devices
    (except the MOTORAZR2 V8 and MOTOROKR Z6)


    "fileconn.dir.photos"
    "fileconn.dir.videos"
    "fileconn.dir.graphics"
    "fileconn.dir.tones"
    "fileconn.dir.music"
    "fileconn.dir.recordings"
    "fileconn.dir.photos.name"
    "fileconn.dir.videos.name"
    "fileconn.dir.graphics.name"
    "fileconn.dir.tones.name"
    "fileconn.dir.music.name"
    "fileconn.dir.recordings.name"

    Share Article : Motorola System Properties
    Share/Save/Bookmark

    Monday, July 13, 2009

    J2ME Bluetooth connection steps


    Following are the connection setup steps for J2ME Bluetooth.
    (example shows Connecting to Server mode connection already
    created with btspp)
    1. Inititate Search for devices.
    2. Method "deviceDiscovered" called by flatform for each device.
    3. Method "inquiryCompleted" called by flatform when device search completes.
    4. Then do a service search for selected device.
    5. Method "servicesDiscovered" called by flatform for each service.
    6. Method "serviceSearchCompleted" called by platform when service search completes.
    7. (there open a StreamConnection to chosen service URL)



    //step 1
    public void SearchAvailDevices() {
    try {
    //First get the local device and obtain the discovery agent.
    m_LclDevice = LocalDevice.getLocalDevice();

    m_DscrAgent = m_LclDevice.getDiscoveryAgent();

    m_DscrAgent.startInquiry(DiscoveryAgent.GIAC, this);
    } catch (BluetoothStateException ex) {
    vobt.addLog("Problem in searching the blue tooth devices : " + ex.getMessage());
    System.out.println("Problem in searching the blue tooth devices");
    ex.printStackTrace();
    }

    }
    //step 2 -- PLATFORM CALL
    //Called when device is found during inquiry
    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {

    try {
    // Get Device Info
    System.out.println("Device Discovered");
    System.out.println("Major Device Class: " + cod.getMajorDeviceClass() + " Minor Device Class: " + cod.getMinorDeviceClass());
    System.out.println("Bluetooth Address: " + btDevice.getBluetoothAddress());
    System.out.println("Bluetooth Friendly Name: " + btDevice.getFriendlyName(true));
    vobt.addLog("**Device Discovered**");
    vobt.addLog("#Major Device Class: " + cod.getMajorDeviceClass() + " Minor Device Class: " + cod.getMinorDeviceClass());
    vobt.addLog("#Bluetooth Address: " + btDevice.getBluetoothAddress());

    //put remote devices in Array
    remoteDevicesArray[deviceCount] = btDevice;
    deviceClassesArray [deviceCount] = cod;
    deviceCount++;
    } catch (Exception e) {
    System.out.println("Device Discovered Error: " + e);
    vobt.addLog("deviceDiscovered : " + e);
    }
    //step 3--PLATFORM CALL
    //when device search completes
    public void inquiryCompleted(int discType) { }
    //step 4
    //Search for srvices in Given device as following
    public void serviceSearch(int selectedIndex)
    {
    try {
    UUID[] uuidSet = new UUID[1];
    uuidSet[0] = RFCOMM_UUID; // UUID USED TO INITIATE SERVER
    int searchID = m_DscrAgent.searchServices(null, uuidSet, remoteDevicesArray[selectedIndex], this);
    } catch (BluetoothStateException ex) {
    ex.printStackTrace();
    vobt.addLog("deviceDiscovered : " + ex);
    }
    }
    // step 5 -- PLATFORM CALL
    //when service found during service search (for each time new service found)
    public void servicesDiscovered(int transID, ServiceRecord[] records) {

    for (int i = 0; i < records.length; i++) {
    m_strUrl = records[i].getConnectionURL(ServiceRecord.AUTHENTICATE_ENCRYPT, false);

    System.out.println(m_strUrl);
    if (m_strUrl.startsWith("btspp")) //search for URLS with btspp
    {
    m_bServerFound = true;
    m_bInitClient = true;
    break;
    }

    }
    }


    // step6 -- PLATFORM CALL
    // when service search complete for given device
    public void serviceSearchCompleted(int transID, int respCode) {
    try { // open stream connection with needed URL
    StrmConn = (StreamConnection) Connector.open(m_strUrl);
    }
    catch()
    {}
    }




    Share Article : J2ME Bluetooth connection steps
    Share/Save/Bookmark