Thanks to Sprint's extensions to the typical URI schemes, you can create links on your website that launch MIDlets installed on visitors phones. Everybody knows about "http:" and you've probably seen "ftp:" and "mailto:" as well. You'll find that Sprint handsets support the "midlet:" scheme which can not only launch a MIDlet, but can also be used as a mechanism to pass data from a website to an application.
The following is a list of the common URI schemes. You've probably seen most of these.
- http, https
- telnet, tn3270, rlogin
- gopher
- file
- ftp
Suppose you have a MIDlet called FooBar installed on your handset. Using the midlet: scheme you can launch the FooBar application when a user selects a link on your web page. The HTML would look like this:
<html> <a href="midlet:FooBar?data_for_foobar">Launch FooBar</a> </html>Now open that web page on your handset browser and select the Launch FooBar link. Amazingly enough, the Java Application Manager will launch the FooBar MIDlet.
Within the FooBar MIDlet, you can put in some code like this:
import com.sprintpcs.util.*;
...
String uri = null;
Muglet ml = null;
ml = Muglet.getMuglet();
if (ml != null)
{
uri = ml.getURI();
}
You will find that uri contains "midlet:FooBar?data_for_foobar". Strip away the "midlet:FooBar?" part and you can process what ever data was passed from the web page.
If you launch FooBar from the application manager (rather than the web page), you'll find ml is null. You can use this technique to determine how a MIDlet was launched.
If you do not have a MIDlet called FooBar installed, your phone may actually prompt you to download one! My Sanyo 4900 directs me here:
http://vm.sprintpcs.com/redirect?request=midlet%3aFooBar
Of course there is no FooBar MIDlet available at that address, but it's nice of the phone to try. Sprint uses this technique to promote MIDlets on their site. If you try to invoke a program that is not already installed on your phone, the application manager will offer to install it for you. Sadly, it only knows to go to Sprint to look for new MIDlets. I wish it would go to my website instead.
The midlet: scheme would allow you to create a service that has both J2ME components and web pages you can access from the mobile browser. You've just learned how the web browser can launch a MIDlet. In another article, you'll see how to Open a Webpage from a MIDlet.