×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    24

    Camera activation using keypad

    myself is student working on project regarding symbian....
    can u help me to activate camera using keypad in J2ME...
    plz....
    thank u.....

  2. #2
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: Camera activation using keypad

    Do you mean to activate a Java MIDlet by pressing a Key ? I don't think it will be possible with Java MIDlets. But will be possible with Symbian C++ apps.

    Regards
    Gopal
    Twitter : @balagopalks
    Linkedin : @balagopalks

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    24

    Re: Camera activation using keypad

    But i did code for activation of camera using midlet i just need to activate that midlet on keypress event isnt it possible in J2ME..? if its possible in symbian c++ can we embed it in J2ME.....?
    Thanks....
    This is the code......


    import javax.microedition.midlet.*;

    //import java.util.TimeZone;
    import javax.microedition.lcdui.*;
    import java.util.*;
    import javax.microedition.media.Manager;
    import javax.microedition.media.Player;
    import javax.microedition.media.control.VideoControl;
    import javax.microedition.media.MediaException;

    import javax.microedition.io.Connector;
    import javax.microedition.io.file.FileConnection;

    import java.io.OutputStream;
    import java.io.IOException;

    public class Midlet extends MIDlet implements CommandListener {

    private Display display;

    // Form where camera viewfinder is placed
    private Form cameraForm;

    // Command for capturing image by camera and saving it.
    // Placed in cameraForm.
    private Command cmdCapture;
    // Command for exiting from midlet. Placed in cameraForm.
    private Command cmdExit;

    // Player for camera
    private Player player;
    // Video control of camera
    private VideoControl videoControl;

    // Alert to be displayed if error occurs.
    private Alert alert;

    /**
    * Constructor.
    */
    public Midlet() {
    InitializeComponents();
    }

    /**
    * Initializes components of midlet.
    */
    private void InitializeComponents() {
    display = Display.getDisplay(this);

    if(checkCameraSupport() == false) {
    showAlert("Alert", "Camera is not supported!", null);
    return;
    }

    try {
    createCameraForm();
    createCamera();
    addCameraToForm();
    startCamera();
    } catch(IOException ioExc) {
    showAlert("IO error", ioExc.getMessage(), null);
    } catch(MediaException mediaExc) {
    showAlert("Media error", mediaExc.getMessage(), null);
    }
    }

    /**
    * Creates and returns form where the camera control will be placed.
    */
    private void createCameraForm() {
    // Create camera form
    cameraForm = new Form("Camera");
    // Create commands for this form
    cmdCapture = new Command("Capture", Command.OK, 1);
    cmdExit = new Command("Exit", Command.EXIT,0);
    // Add commands to form
    cameraForm.addCommand(cmdCapture);
    cameraForm.addCommand(cmdExit);
    // Set midlet as command listener for this form
    cameraForm.setCommandListener(this);
    }

    /**
    * Check camera support.
    * @return true if camera is supported, false otherwise.
    */
    private boolean checkCameraSupport() {
    String propValue = System.getProperty("supports.video.capture");
    return (propValue != null) && propValue.equals("true");
    }

    /**
    * Creates camera control and places it to cameraForm.
    * @throws IOException if creation of player is failed.
    * @throws MediaException if creation of player is failed.
    */
    private void createCamera() throws IOException, MediaException {
    player = Manager.createPlayer("capture://devcam1");
    player.realize();
    player.prefetch();

    videoControl = (VideoControl)player.getControl("VideoControl");
    }

    /**
    * Adds created camera as item to cameraForm.
    */
    private void addCameraToForm() {
    cameraForm.append((Item)videoControl.
    initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));
    }

    /**
    * Start camera player
    * @throws IOException if starting of player is failed.
    * @throws MediaException if starting of player is failed.
    */
    private void startCamera() throws IOException, MediaException {
    if(player.getState() == Player.PREFETCHED) {
    player.start();
    }
    }

    /**
    * Saves image captured by camera.
    */
    private void captureAndSaveImage() {
    FileConnection file = null;
    OutputStream outStream = null;

    try {
    if(checkPngEncodingSupport() == false) {
    throw new Exception("Png encoding is not supported!");
    }

    // Capture image
    byte[] capturedImageData =
    videoControl.getSnapshot("encoding=png");

    // Get path to photos folder.
    String dirPhotos = System.getProperty("fileconn.dir.photos");
    if(dirPhotos == null) {
    throw new Exception("Unable get photos folder name");
    }

    Calendar calendar = Calendar.getInstance();
    //calendar.setTimeInMillis(System.currentTimeMillis());
    String date = Integer.toString(calendar.get(calendar.DATE));
    String time = Integer.toString(calendar.get(calendar.SECOND));
    String hour = Integer.toString(calendar.get(calendar.HOUR));
    String minute = Integer.toString(calendar.get(calendar.MINUTE));
    String milsecond = Integer.toString(calendar.get(calendar.MILLISECOND));
    // Date time = getDate();
    String fileName = dirPhotos + date + hour + minute + time + milsecond + ".png";
    // Open file
    file = (FileConnection)Connector.open(fileName,
    Connector.READ_WRITE);
    // If there is no file then create it
    if(file.exists() == false) {
    file.create();
    }
    // Write data received from camera while making snapshot to file
    outStream = file.openOutputStream();
    outStream.write(capturedImageData);

    showAlert("Info", "Image is saved in " + fileName, cameraForm);

    } catch(IOException ioExc) {
    showAlert("IO error", ioExc.getMessage(), cameraForm);
    } catch(MediaException mediaExc) {
    showAlert("Media error", mediaExc.getMessage(), cameraForm);
    } catch(Exception exc) {
    showAlert("Error", exc.getMessage(), cameraForm);
    } finally {
    // Try to close file
    try {
    if(outStream != null) {
    outStream.close();
    }
    if(file != null) {
    file.close();
    }
    } catch(Exception exc) {
    // Do nothing
    }
    }
    }

    /**
    * Checks png encoding support
    * @return true if png encoding is supported false otherwise.
    */
    private boolean checkPngEncodingSupport() {
    String encodings = System.getProperty("video.snapshot.encodings");
    return (encodings != null) && (encodings.indexOf("png") != -1);
    }

    /**
    * From MIDlet.
    * Signals the MIDlet that it has entered the Active state.
    */
    public void startApp() {
    if ( videoControl != null ) {
    display.setCurrent(cameraForm);
    }
    }

    /**
    * From MIDlet.
    * Signals the MIDlet to enter the Paused state.
    */
    public void pauseApp() {
    // TODO: pause player if it is running.
    }

    /**
    * Performs exit from midlet.
    */
    public void exitMIDlet() {
    notifyDestroyed();
    }

    /**
    * Shows alert with specified title and text. If next displayable is not
    * specified then application will be closed after alert closing.
    * @param title - Title of alert.
    * @param message - text of alert.
    * @param nextDisp - next displayable. Can be null.
    */
    private void showAlert(String title, String message, Displayable nextDisp) {
    alert = new Alert(title);
    alert.setString(message);
    alert.setTimeout(Alert.FOREVER);

    if(nextDisp != null) {
    display.setCurrent(alert, nextDisp);
    } else {
    display.setCurrent(alert);
    alert.setCommandListener(this);
    }
    }

    /**
    * From MIDlet.
    * Signals the MIDlet to terminate and enter the Destroyed state.
    */
    public void destroyApp(boolean unconditional) {
    if(player != null) {
    player.deallocate();
    player.close();
    }
    }

    /**
    * From CommandListener.
    * Indicates that a command event has occurred on Displayable displayable.
    * @param command - a Command object identifying the command.
    * @param displayable - the Displayable on which this event has occurred.
    */
    public void commandAction(Command command, Displayable displayable) {
    // Handles "Capture image" command from cameraForm
    if(command == cmdCapture) {
    captureAndSaveImage();
    }
    // Handles "exit" command from forms
    if(command == cmdExit) {
    exitMIDlet();
    }
    // Handle "ok" command from alert
    if(displayable == alert) {
    exitMIDlet();
    }
    }
    }

    /**
    * @author Manish1
    */

  4. #4
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: Camera activation using keypad

    Its not possible to launch/start MIDlet with a Keypress. The tough workaround would be to launch it with a Symbian C++ app.

    There are couple of entries in Wiki including this Launching MIDlets programmatically on S60 3rd Edition

    Regards
    Gopal
    Twitter : @balagopalks
    Linkedin : @balagopalks

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    24

    Re: Camera activation using keypad

    Thanks i will try this......

Similar Threads

  1. Python for S60 1.4.0 released
    By jplauril in forum Symbian
    Replies: 43
    Last Post: 2009-05-24, 09:22
  2. Nokia N-Series Complete Model Line-Up
    By Dopod in forum General Development Questions
    Replies: 6
    Last Post: 2008-07-22, 20:16
  3. activation key expired-Encryption method:AES128CBC
    By b_anand in forum Digital Rights Management & Content Downloading
    Replies: 1
    Last Post: 2008-04-05, 08:19
  4. Camera API on Symbian 9.1 (Nokia N80)
    By srigans1 in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2007-10-20, 05:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×