package test; import javax.microedition.io.ConnectionNotFoundException; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.midlet.*; /** * MIDlet 打开内置浏览器 * NOKIA 测试通过 */ public class wap extends MIDlet implements CommandListener { private Command exit; private Command open; private Form form; private Display display; public wap() { display = Display.getDisplay( this ); form = new Form("打开内置浏览器"); exit = new Command("退出",Command.EXIT,0); open = new Command("打开",Command.OK,1); form.addCommand( exit ); form.addCommand( open ); form.setCommandListener( this ); } public void startApp() { display.setCurrent( form ); } public void pauseApp() { } public void destroyApp( boolean unconditional ) { this.notifyDestroyed(); } public void openWap() { try { // this.platformRequest( "http://www.baidu.com/" );//这个可以 // this.platformRequest( "www.baidu.com" );//这样写不行 this.platformRequest( "http://wap.baidu.com/" ); } catch( ConnectionNotFoundException ex ) { ex.printStackTrace(); } } public void commandAction( Command c, Displayable d ) { if( c == exit ) { this.destroyApp( false); } else if( c == open ) { this.openWap(); this.destroyApp( false); } } }
文章转自 http://hi.baidu.com/wishwingliao/blog/item/9c04bd385d315ecad56225f0.html