Monday, August 16, 2010

How to get device IMEI number using JavaME for different vendors?

The International Mobile Equipment Identity (IMEI) is a number unique to every GSM, WCDMA, and iDEN mobile phone, as well as some satellite phones. It is usually found printed inside the battery compartment of the phone. It can also be displayed on the screen of the phone by entering *#06# into the keypad on most phones.

To retreive same information using JavaME is as follows:
As you all know that, MIDP (Mobile Information Device Profile) when combined with CLDC provides a Java Runtime Environment and a rich set of Java APIS for cell phones. MIDP defines some System properties that are available to the midlet with java.lang.System.getProperty(...) method. As IMEI is manufacturer specifc so there are few manufacturer specific APIs using which you can retrieve this info. Here's how to get IMEI number from mobile devices of different manufacturers:

1. Nokia
* System.getProperty("phone.imei");
* System.getProperty("com.nokia.imei");
* System.getProperty("com.nokia.mid.imei"); //especially for S40 devices
2. Note: Requires signed MIDlet. S60 3rd edition device does not requires signing to fetch this info.On Series 40 phones this requires that your MIDlet is signed to either operator or manufacturer domain, and this is only available in Series 40 3rd Edition, FP1 devices and newer. Sony Ericsson
* System.getProperty("com.sonyericsson.imei");
3. Samsung
* System.getProperty("com.samsung.imei");
4. Motorola
* System.getProperty("IMEI");
* System.getProperty("com.motorola.IMEI");
5. Siemens
* System.getProperty("com.siemens.IMEI");
6. LG
* System.getProperty("com.lge.imei");

In addition to this, there are some generic information about the device that can be retrieved by using System.getProperty(propertyString) method call, where value of propertyString can be vary as per your requirement. Few of them are listed as below:-

1. microedition.profiles
2. microedition.configuration
3. microedition.locale
4. microedition.platform

For more information see MIDP System Properties & J2ME Defined System Properties

Thursday, August 5, 2010

Call Javascript from a Java applet

Netscape only, using the javascript: protocol
A Javascript function is called from Java by using the showDocument method. A URL is needed with "javascript:" as the protocol.
[Java applet]
import java.applet.*;
import java.net.*;

public class InJava4 extends Applet{
  public void init(){
    String msg = "Hello from Java (using javascript alert)";
    try {
      getAppletContext().showDocument
        (new URL("javascript:doAlert(\"" + msg +"\")"));
      }
    catch (MalformedURLException me) { }
  }
}
[Javascript and HTML]


        NAME="myApplet"  MAYSCRIPT
        HEIGHT=10 WIDTH=10>
Try it here Netscape and IE ok, using the netscape.javascript.JSObject package
How to compile when using the netscape.javascript.JSObject package ?

For Java 1.4.2 and later: add plugin.jar to your classpath. It can be found in the lib directory of your JRE installation, e.g. C:\Program Files\Java\jre1.5.0\lib\plugin.jar
For Java 1.4.0/1.4.1: use jaws.jar (same directory).
In the following example, you type in the TextField a Javascript function and press the button to execute the function. For example, try alert('Hello from JAVA'). Or you can execute function defined on the same page as the Applet. The Applet must contains the MAYSCRIPT parameter to be able to use JSObject.
Netscape and IE Ok.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import netscape.javascript.*;

public class InJava5 extends Applet implements ActionListener {
  Button b;
  TextField t;

  public void init() {
     t = new TextField(20);
     add(t);
     b = new Button("execute Javascript");
     add(b);
     b.addActionListener(this);
     }

  public void actionPerformed(ActionEvent ae) {
     if (ae.getSource() == b) {
       JSObject win = (JSObject) JSObject.getWindow(this);
       win.eval(t.getText());
       }
     }
}
Try it here Another way is to use the Reflection API. That way you don't need to modify your CLASSPATH for compilation or even import the netscape.jsobject package.
// posted by C Werner on the realhowto list
import java.lang.reflect.*;
...
// Somewhere in the applet class ...
...
String jscmd = "window.close()";  /* JavaScript command */
String jsresult = null;
boolean success = false;
try {
  Method getw = null, eval = null;
  Object jswin = null;
  Class c =
    Class.forName("netscape.javascript.JSObject"); /* does it in IE too */
  Method ms[] = c.getMethods();
  for (int i = 0; i < ms.length; i++) {
      if (ms[i].getName().compareTo("getWindow") == 0)
         getw = ms[i];
      else if (ms[i].getName().compareTo("eval") == 0)
         eval = ms[i];
      }
  }
  Object a[] = new Object[1];
  a[0] = this;               /* this is the applet */
  jswin = getw.invoke(c, a); /* this yields the JSObject */
  a[0] = jscmd;
  Object result = eval.invoke(jswin, a);
  if (result instanceof String)
    jsresult = (String) result;
  else
    jsresult = result.toString();
  success = true;
  }

catch (InvocationTargetException ite) {
  jsresult = "" + ite.getTargetException();
  }
catch (Exception e) {
  jsresult = "" + e;
  }

if (success)
    System.out.println("eval succeeded, result is " + jsresult);
else
    System.out.println("eval failed with error " + jsresult);

3 easy steps to self-sign a Applet Jar file

From link .

1. keytool -genkey -keystore myKeyStore -alias me

2. keytool -selfcert -keystore myKeyStore -alias me

3. jarsigner -keystore myKeyStore jarfile.jar me

Monday, August 2, 2010

What Is - Appropriate version of the BlackBerry JDE


Description

When creating and building your application, it is important to choose the correct version of the BlackBerry JDE to make sure that the application is compatible with the target BlackBerry smartphones. Applications built in the BlackBerry JDE are forward-compatible with newer BlackBerry Device Software versions, but they are not backward-compatible with older versions.
For example, an application built in BlackBerry JDE 4.1 runs on a BlackBerry smartphones running BlackBerry® Device Software 4.1 and later. It does not run on a BlackBerry smartphones running BlackBerry Device Software 4.0. Thus, when building applications, you should use a BlackBerry JDE version that matches the lowest version of BlackBerry Device Software you want to support.
Note: To verify the version of BlackBerry Device Software installed on the BlackBerry smartphone, select Options > About.


Applications developed using the BlackBerry JDE are forward-compatible but not backward-compatible. In other words, an application developed with JDE 4.1 will run on BlackBerry devices with device software version 4.1 and later; however, they will not run on device software 4.0.