This is a presentation that I made, which will help anyone new to Java ME platform as a gentle introduction guide. Please comment your opinion.
There are many situations where you may want to know your phone's IP Address. You know that your mobile connects over GPRS which in turn is based on Internet Protocol, so you are pretty confident that the phone has an IP Address.
Well then, there is a good news and a bad news for you. The good news is that your phone do have an IP Address. The bad news is that this IP address will be hardly usefull for you. Why? read on.
The above image shows the network layout of most mobile based IP connection. Your mobile handset will be connected to the service provider's NAT gateway. The IP that your mobile handset get is a private IP, means that this IP can't be reached from external world.
There are ways to get both your private IP and the IP Address of the NAT gateway.
Getting your IP Address
1)The following snippet will give you your private IP Address.
Games and most applications in the Windows world come with a
trial period, during which you can test the application. If you find the
application to your taste, you can purchase the full application, which is
usually a simple serial key to unlock the application.
There have been several attempts to adapt such a method to
the mobile programming world. However, it’s not easy to generate a foolproof
method as the computing power required to generate a strong hash (read as
serial number) or to verify it, is limited in a mobile device. The major
difficulty lies in generating a number, which is unique to a mobile.
But Hey, we don’t want to *create* a new number. We already
have a unique number for every device, which is the IMEI number. Why not use
The only difficulty is that Java ME doesn’t expose any
standard API to get the IMEI number of the device. However, most manufactures allow
us to get the IMEI number using the System.getProperty() method. Here is a HowTo:
o you are determined in becoming an 31337 Java ME guru, as is evident that you have begun reading the "Java ME Advanced Tutorial" series. If you haven't read the "Java ME Beginner's Tutorial" series, now would be a good time to skim through it. By the time you start the advanced tutorials, you should be well versed with using Wireless Tool Kit, Java ME Basics, writing code and building it and packaging it. Now we are going into advanced areas of Java ME technology. Let's begin with GUI programming.
Little Background Info
The first version of Java released outside Sun was Java 1.0.2. This initial version itself contained AWT(Abstract Windowing Toolkit), which was a means to develop Graphical User Interface (GUI) applications. Later came Swing, which was a better AWT than AWT.
Java ME do not use AWT or Swing. Instead it defines its own GUI classes which are part of the MIDP api. Reason for not using AWT or Swing are:
Classes for GUI programming are defined within the MIDP APIs.
Due to these reasons MIDP decided to have its own set of GUI APIs. These APIs are classified as high level and low level APIs. Both the high level and low level APIs come in the javax.microedition.lcdui package.
Anything that can be displayed is represented by the Diplayable class. The Screen class is a sub-class of the Displayable class and represent screens that occupy the full screen area. There are three types of screens:
The first step in GUI programming is to get the display object. Yes, as you might have guessed, the display object represent the display of the mobile device. The general routine in GUI programming is:
public static Display getDisplay(Midlet midlet);
Things to remember:
public void setCurrent(Displayable nextDisplayable);
public void setCurrent(Alert alert, Displayable nextDisplayable);
Display class - In detail
We have already seen some of the methods in the Display class: getDisplay() and setCurrent(). Some other most useful methods are discussed here:
public Displayable getCurrent()
This returns the Displayable object that is currently being displayed on the screen. If you call this before setting a screen using setCurrent, it will return NULL.
If the screen is hidden by a system screen(such as a low battery Alert screen), still getCurrent() will return the Displayable that was last set using setCurrent().
public boolean isColor()
This returns true, if the phone is a color phone. Else, this returns false.
public int numColors()
This returns the number of colors if the phone is a color phone. Otherwise, it returns the number of gray levels supported.
public void setCurrentItem(Item item)
This is a very useful method when you are using forms. Suppose you have a form with two TextEntries - Name and Password, and you wish that the cursor be in the Name field when the form is displayed. All you have to do is : d.setCurrentItem(name);
public boolean vibrate(int duration)
This method can be used to enable and disable the vibrator of a phone. If the phone doesn't support vibration or if your display is not in the foreground then this call returns false. Otherwise it returns true. This method returns immediately and is not a blocking call. It accepts the time in milliseconds for which the vibrator should be active. However, the implementation can limit or override this duration. If this parameter is zero, vibrator is stopped.
public boolean flashBacklight(int duration)
This is very much similar to the vibrate() call. It is used to turn on and off the devices' flashlight repeatedly for the duration specified in the parameter. If the parameter is zero the light is turned off immediately. This method is non blocking and returns false if the display is not in the foreground or if the back light cannot be controlled by application. Else it returns true.
In the next section, we begin with the high level api.
<< Java ME Advanced Tutorial: Table Of Contents