×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    7

    File browser Problem

    Hi All,
    I created a file browser midlet to browse the mobile's files and open a file..
    i used jsr 75
    the Application worked very good on emulators WTK2.2 & WTK2.5

    BUT

    I tried it on nokia phones n70,n72,n73,6630 ... didn't work on any of them
    it just shows me a list containing the memory card, phone memory & if i selected one of them no folders are opened

    i tried the solution of controlling the access mode from the mobile: manager-> suitesettings-> ask every time
    but didin't work too...

    plzzzzzzzzzz helpp me it's so urgent 4 me...
    thanks

  2. #2
    Regular Contributor
    Join Date
    Mar 2006
    Posts
    124

    Re: File browser Problem

    Why don't you post the code you use to open/read folders ?
    Are you able to access and open a file by name ?

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    7

    Re: File browser Problem

    this is my code:

    public class MobileXplorer2 extends MIDlet implements CommandListener
    {
    // For our file system, this will be our root
    private final static String ROOT = "/";

    // Definitions for directories
    private final static String DIRECTORY_INDICATOR = "/";
    private final static String UP_DIRECTORY_INDICATOR = "..";

    // Holds the full path to the current directory.
    // Point to the root at app startup
    private String fullPath = ROOT;

    // Our main display object
    // List of files/directories in the current directory
    List lstDirectory = null;

    // Icons for directory, file, and move-up-one directory
    Image imgDirectory = null, imgFile = null, imgUpDirectory = null;

    private Command cmExit; // Command to exit
    private Command cmSelect; // Command to select dir or file
    private Command cmBack; // Command to "go back" one "screen"

    /*--------------------------------------------------
    * It all starts here. Check for FileConnection API,
    * get images, create commands and allocate List
    *-------------------------------------------------*/
    public MobileXplorer2()
    {
    if (System.getProperty("microedition.io.file.FileConnection.version") == null)
    {
    System.out.println("FileConnection API not available");
    destroyApp(false);
    notifyDestroyed();
    }
    else
    {
    // Store references to our images for files and directories
    try
    {
    imgFile = Image.createImage("/file.png");
    imgDirectory = Image.createImage("/directory.png");
    imgUpDirectory = Image.createImage("/up_directory.png");
    }
    catch(IOException e)
    { }

    // Allocate the List that will hold directory contents
    lstDirectory = new List(fullPath, List.IMPLICIT);

    // Add commands and listen for events
    cmSelect = new Command("Select", Command.ITEM, 1);
    cmExit = new Command("Exit", Command.EXIT, 2);
    cmBack = new Command("cmBack", Command.BACK, 3);
    lstDirectory.addCommand(cmExit);
    lstDirectory.addCommand(cmSelect);
    lstDirectory.setCommandListener(this);

    // Default command when selecting an entry in the List
    lstDirectory.setSelectCommand(cmSelect);
    }
    }

    /*--------------------------------------------------
    * Get list of roots and display the List object
    *-------------------------------------------------*/
    public void startApp()
    {
    // Create a list of root directories
    getRootDirectories();

    // The List is our main displayable
    Display.getDisplay(this).setCurrent(lstDirectory);
    }

    public void pauseApp()
    {
    }

    public void destroyApp(boolean cond)
    {
    notifyDestroyed();
    }

    /*--------------------------------------------------
    * Create a list of the valid root directories
    *-------------------------------------------------*/
    private void getRootDirectories()
    {
    // Get roots
    Enumeration enumu = FileSystemRegistry.listRoots();

    // Clear out the existing List contents
    lstDirectory.deleteAll();

    // Store entries in vector
    while(enumu.hasMoreElements())
    {
    String root = (String) enumu.nextElement();
    lstDirectory.append(root, imgDirectory);
    }
    }

    /*--------------------------------------------------
    * Build list of files in the specified directory
    *-------------------------------------------------*/
    private void buildFileList(String dir)
    {
    String fname;
    Enumeration enume;
    FileConnection fc = null;

    try
    {
    // Open connection to the specified directory
    fc = (FileConnection) Connector.open("file://" + dir,Connector.READ_WRITE);

    // Enumerate the list of returned files/directories
    enume = fc.list("*", true);

    // Clear out the existing List contents
    lstDirectory.deleteAll();

    // Show image that represents going up one directory level
    lstDirectory.append("..", imgUpDirectory);

    // Loop through all entries, building a List
    while(enume.hasMoreElements())
    {
    fname = (String) enume.nextElement();

    // Open connection
    fc = (FileConnection) Connector.open("file://" + dir + "/" + fname,Connector.READ_WRITE);

    // Append the name, along with an indicator to the List,
    // specifying if the entry is a file or directory
    lstDirectory.append(fname, fc.isDirectory() ? imgDirectory : imgFile);
    }

    fc.close();

    }
    catch (Exception e)
    { }
    }

    /*--------------------------------------------------
    * Directory selected, change to the directory
    *-------------------------------------------------*/
    void changeToDirectory(String dirname)
    {
    // Selected ".." directory, move up the tree
    if (dirname.equals(UP_DIRECTORY_INDICATOR))
    {
    // Locate the next to last separator so we can remove the path
    char separator = fullPath.charAt(0);
    int x = fullPath.lastIndexOf(separator, (fullPath.length() - 2));

    // Remove the last path entry, as we are moving up the tree
    fullPath = fullPath.substring(0, x + 1);
    }
    else // Drilling down the directory tree
    {
    // Update variable that holds the full directory path
    fullPath += dirname;
    }

    // We worked our way up the tree back to the root,
    // build list of roots
    if (fullPath.length() == 1)
    getRootDirectories();
    else
    // Build a list of files/dir given the new path
    buildFileList(fullPath);

    // Show the new List
    Display.getDisplay(this).setCurrent(lstDirectory);
    }

    /*--------------------------------------------------
    * File selected, show its properties
    *-------------------------------------------------*/
    void displayFileProperties(String fullPath, String filename)
    {
    try
    {
    FileConnection fc = (FileConnection) Connector.open(fullPath,Connector.READ_WRITE);

    // Build an alert to show file properties
    Alert fileinfo = new Alert(filename,
    "Last Modified " + new Date(fc.lastModified()) + "\n" +
    "Write access: " + (fc.canWrite() ? "yes" : "no") + "\n" +
    "Read access: " + (fc.canRead() ? "yes" : "no") + "\n" +
    "File size: " + fc.fileSize(),
    null, AlertType.INFO);

    // Wait for user acknowledgement
    fileinfo.setTimeout(Alert.FOREVER);

    // Show the alert
    Display.getDisplay(this).setCurrent(fileinfo);

    fc.close();
    }
    catch (IOException ioe)
    { }

    }

    /*--------------------------------------------------
    * Manage commands
    *-------------------------------------------------*/
    public void commandAction(Command c, Displayable s)
    {
    if (c == cmSelect)
    {
    // Get a reference to the selected List entry
    String str = lstDirectory.getString(lstDirectory.getSelectedIndex());

    // Depending on whether a file or directory was selected...
    // Valid directories are "/" or ".."
    if(str.endsWith(DIRECTORY_INDICATOR) || str.equals(UP_DIRECTORY_INDICATOR))
    changeToDirectory(str);
    else
    {
    // Pass in the full path (including the selected file name)
    // as well as the filename itself
    displayFileProperties("file://" + fullPath + str, str);
    }
    }
    else if (c == cmExit)
    {
    destroyApp(false);
    notifyDestroyed();
    }
    }
    }

Similar Threads

  1. Recognizer in S60 3rd, problem with wap browser
    By bobbycalf in forum Symbian
    Replies: 4
    Last Post: 2009-03-17, 15:28
  2. Problem with .mbg file
    By ticktock in forum Symbian User Interface
    Replies: 3
    Last Post: 2007-03-26, 22:05
  3. KHTML Browser bug?
    By presentTech in forum Symbian
    Replies: 2
    Last Post: 2006-09-07, 21:15
  4. Recognizer in S60 3rd, problem with wap browser
    By bobbycalf in forum Mobile Java General
    Replies: 2
    Last Post: 2006-08-25, 20:29
  5. Animation problem in 3D(m3g file)
    By Nailos in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2005-07-20, 14:19

Posting Permissions

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