Join Now
Quality Rating:
  • Currently 3.0 / 5
(3.0 / 5 - 1 vote cast)
Expertise Level:
  • Currently 2.0 / 5
(2.0 / 5 - 1 vote cast)

This page was last modified 20:30, 9 October 2008.

CS000957 - Flashing the backlight

From Forum Nokia Wiki



ID CS000957 Creation date May 14, 2008
Platform S60 3rd Edition, MR
S60 3rd Edition, FP1
Tested on devices Nokia E61i
Nokia N95 8GB
Category Java ME Subcategory Hardware


Keywords (APIs, classes, methods, functions): javax.microedition.lcdui.Display, javax.microedition.lcdui.Display.flashBacklight()

Overview

This snippet demonstrates how to flash the backlight of the device for a specified duration. In practice, the MIDlet constructs a menu item through which the user can flash the backlight.

Source

Flashing the backlight can be implemented as follows:

// Flash the backlight for 5 seconds
Display.getDisplay(this).flashBacklight(5000);

Here is a complete example:

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;
public class ExampleMIDlet extends MIDlet implements CommandListener {
    private Command flashCommand;
    private Command exitCommand;
    private Form mainForm;
 
    /**
     * Constructor. Constructs the object and initializes displayables.
     */
    public ExampleMIDlet() {
        mainForm = new Form("ExampleMIDlet");
        
        flashCommand = new Command("Flash", Command.SCREEN, 0);
        mainForm.addCommand(flashCommand);
        
        exitCommand = new Command("Exit", Command.EXIT, 0);
        mainForm.addCommand(exitCommand);
        
        mainForm.setCommandListener(this);
    }
    
    /**
     * Called when the MIDlet is started.
     */
    public void startApp() {
        Display.getDisplay(this).setCurrent(mainForm);
    }
    
    // Other inherited methods omitted for brevity
    // ...
    
    /**
     * From CommandListener.
     * Called by the system to indicate that a command has been invoked on a
     * particular displayable.
     * @param command the command that was invoked
     * @param displayable the displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {
        if (command == flashCommand) {
            // Flash the backlight for 5 seconds
            boolean flashAllowed = Display.getDisplay(this).flashBacklight(5000);
            if (!flashAllowed) {
                // TODO: Flashing is not allowed. Inform the user.
            }
        } else if (command == exitCommand) {
            // Exit the MIDlet
            destroyApp(true);
            notifyDestroyed();
        }
    }

Postconditions

If the user selects the Flash menu item, the backlight is flashed for 5 seconds.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Sensors, LED/backlight controlling Qratman Python 1 2008-09-05 12:00
Java turn backlight off on S40 sirisak_b2 Mobile Java General 1 2008-06-16 05:01
How to set Light n vibarate for nokia 6600 ?? stp_chen Mobile Java General 6 2005-09-22 14:50
7650 Vibration Fuction at Java Games bennytong Mobile Java General 2 2002-10-09 07:06
Nokia 12 CORBA bug? kleva2 Nokia M2M 11 2005-07-16 14:00
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZhardwareQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX