Monday, July 11, 2011

JavaMe Tips: FileConnection API useful methods

Hello all. Today I'm going to show you two very useful methods when working with the FileConnection API for JavaMe. This methods along with others not described in this post, can help you a lot:

  
  //inside a class...

  /**
   * Checks whether the device has support for the 
   * FileConnection API
   * @return true if and only if the device supports the API
   * false otherwise
   */
  private boolean checkFileSupport() {
    if (System.getProperty(
       "microedition.io.file.FileConnection.version") != null)
    {
      return true;
    }
    return false;
  }

The last method tells you whether the device has support for the FileConnection API. Pretty handy when the application is developed for a wide range of mobile devices.
Next, we'll see a method that returns all the possible drives where the files can be stored in the mobile device.

  
   //inside a class...

  /**
   * Asks for the list of drivers where files can be stored
   * @return Vector of Strings representing the name of
   * the drives where files can be stored
   */
  private Vector getRoots() {
    Vector vRoots = new Vector();

    if (checkFileSupport()) {
      Enumeration drivers = FileSystemRegistry.listRoots();
      while (drivers.hasMoreElements()) {
        vRoots.addElement((String) drivers.nextElement());
      }
    }
    return vRoots;
  }

Imagine your application takes snapshots, and you want to ask the user where to store them... with the help of the last method  and a List, you can show to the user all the possible "hard drives" where he/she can save their pictures.

see ya soon!

References:

Getting Started with the FileConnection APIs. December 2004. Oracle [online].
Available on Internet: http://developers.sun.com/mobility/apis/articles/fileconnection/
[accessed on February 26 2011].

Working with the Java ME FileConnection API on Physical Devices. March 2007. Java.net[online].
Available on Internet: http://today.java.net/article/2007/03/27/working-java-me-fileconnection-api-physical-devices
[accessed on February 26 2011].

4 comments:

  1. hello.. sir.. can a ask a favor. i hope you had a time to answer my question. i also used J2ME for computer vision. I need to capture a tomato and analyze the ripeness of the tomato. i used netbeans 7.0 and jdk 1.6..
    can you teach me how to do. i need you help. hope you can read my comment. thank a lot..

    ReplyDelete
  2. Hello Anonymous. I supposed you are going to decide based on the color of the tomato, right? Check my email in my profile, so we can discuss a little bit about this application via email.

    bye

    ReplyDelete
  3. hello sir. i cannot connect on your email. this your email rigth @aa_lopez?. I supposed going to based on the color og tomato. and my problem is to capture the tomato. i had a code but it cannot save the image.

    ReplyDelete
  4. Anonymous, you could find my profile and email in this URL:

    http://www.blogger.com/profile/05599815066202691589

    contact me so we can discuss better about this application.

    ReplyDelete