請注意:對於UIQ3的手機,例如W950 M600等,可以從控制面板來禁止屏幕保護程序,因此Nokia UI API不再適合。
還需要注意的是由於我們並非在程序中禁止屏幕保護程序,而是中斷其運行。因此要在循環中不停的調用setLights()方法。
DeviceControl.setLights(0, 100);
下面是一個案例
import com.nokia.mid.ui.DeviceControl; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class BacklightWorkaround extends MIDlet { private SimpleCanvas canvas; /** * Keeps the backlight on by repeatedly setting */ class LightThread extends Thread { public void run() { while(true){ DeviceControl.setLights(0, 100); try { Thread.sleep(5000); } catch (InterruptedException ex) { ex.printStackTrace(); } } } } private class SimpleCanvas extends Canvas implements CommandListener{ private Command exitCmd; private MIDlet midlet; public SimpleCanvas(MIDlet midlet) { this.midlet = midlet; exitCmd = new Command("Exit",Command.EXIT, 1); addCommand(exitCmd); setCommandListener(this); } public void paint(Graphics g) { g.drawString("Let there be light.", 0, 0, Graphics.LEFT|Graphics.TOP); } public void commandAction(Command command, Displayable displayable) { if(command == exitCmd){ midlet.notifyDestroyed(); } } } public void startApp() { if(canvas == null){ canvas = new SimpleCanvas(this); new LightThread().start(); } Display.getDisplay(this).setCurrent(canvas); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } } |