×

Discussion Board

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

    File Browsing 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

    here is the 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();
    }
    }
    }

  2. #2
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: File Browsing Problem

    Take a look at the example application in this guied, the FileConnection API Developer's Guide (with Example) v2.0: http://www.forum.nokia.com/info/sw.n..._0_en.zip.html

    Will it run on the specified phones?

  3. #3
    Regular Contributor
    Join Date
    Dec 2004
    Posts
    231

    Re: File Browsing Problem

    Hi,
    there is a difference in expressing the path for open a connection between wtk25 and nokia : I would suggest to make sure your path is the whole and correct path by putting it in output to the console(System.out) and checking it.

    Best Regards

  4. #4
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: File Browsing Problem

    Hi Marwa,
    roots in wtk and nokia are different.where wtk shows root1 and nokia has c: and d:.Not all folders can be browsed in case of nokia.it has restrictions there.i suppose images folder and its sub folders can only be browsed.check this with reading a file in each folder and if it cant it will throw an exception .check this with each folder.

    Thanks
    Soku

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

    Thumbs up Re: File Browsing Problem

    Hi All,

    Thanksssss alot for Ur help

    The problem is solved (Y)

    Thankss (F)

    Marwa

  6. #6
    Regular Contributor
    Join Date
    Jul 2007
    Location
    Brisbane, Australia
    Posts
    158

    Re: File Browsing Problem

    how exactly did you solve the problem marwa?

  7. #7
    Registered User
    Join Date
    May 2007
    Posts
    2

    Re: File Browsing Problem

    Hi

    I a also facing the same problem in Nokia n70 , only the directoy are diplay but not the sub directory and image , kindly help , so waht shoulr be th connector.open path

    Thanks

    Milan

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

    Re: File Browsing Problem

    Quote Originally Posted by milanexe
    Hi

    I a also facing the same problem in Nokia n70 , only the directoy are diplay but not the sub directory and image , kindly help , so waht shoulr be th connector.open path

    Thanks

    Milan
    Hi milanexe! Welcome to Nokia Developer discussion Boards!!

    May be these docs on FileConnection could help!

    MIDP: FileConnection API Developer's Guide (with Example) v2.0
    http://www.forum.nokia.com/info/sw.n..._0_en.zip.html

    Hope this blog is also of some interest
    http://blogs.forum.nokia.com/view_entry.html?id=131

    Are you getting any exceptions? What is the path you are trying to open?

    Regards
    Gopal

    __________________
    MobiQuil.com
    An initiative by Developers for Developers.
    http://www.mobiquil.com - Alpha - Launched.

  9. #9
    Registered User
    Join Date
    May 2007
    Posts
    2

    Re: File Browsing Problem

    Hi BalaGopalks thanks for your reply . I am sending My code

    ---------------------------------

    /**
    * Show file list in the current directory .
    */
    void showCurrDir() {
    Enumeration e;
    FileConnection currDir = null;
    List browser;

    try {
    if (MEGA_ROOT.equals(currDirName)) {
    e = FileSystemRegistry.listRoots();
    browser = new List(currDirName, List.IMPLICIT);
    } else {
    currDir = (FileConnection)Connector.open("file://" +"localhost" + currDirName);
    e = currDir.list();
    browser = new List(currDirName, List.IMPLICIT);
    // not root - draw UP_DIRECTORY
    browser.append(UP_DIRECTORY, dirIcon);
    }

    while (e.hasMoreElements()) {
    String fileName = (String)e.nextElement();

    if (fileName.charAt(fileName.length() - 1) == SEP) {
    // This is directory
    browser.append(fileName, dirIcon);
    // browser.setSelectCommand(view);

    } else {
    // this is regular file
    browser.append(fileName, fileIcon);
    browser.setSelectCommand(SEND_CMD);

    }

    }


    browser.setSelectCommand(view);
    //Do not allow creating files/directories beside root
    if (!MEGA_ROOT.equals(currDirName)) {
    }

    browser.setCommandListener(this);
    if (currDir != null) {
    currDir.close();
    }

    Display.getDisplay(this).setCurrent(browser);
    } catch (IOException ioe) {
    ioe.printStackTrace();
    }
    }

    void traverseDirectory(String fileName) {
    /* In case of directory just change the current directory
    * and show it
    */
    if (currDirName.equals(MEGA_ROOT)) {
    if (fileName.equals(UP_DIRECTORY)) {
    // can not go up from MEGA_ROOT
    return;
    }

    currDirName = fileName;
    } else if (fileName.equals(UP_DIRECTORY)) {
    // Go up one directory
    // TODO use setFileConnection when implemented
    int i = currDirName.lastIndexOf(SEP, currDirName.length() - 2);

    if (i != -1) {
    currDirName = currDirName.substring(0, i + 1);
    } else {
    currDirName = MEGA_ROOT;
    }
    } else {
    currDirName = currDirName + fileName;
    }

    showCurrDir();
    }

    void showFile(final String fileName) {
    System.out.println("file name===="+fileName);
    DataInputStream dis;


    try {
    FileConnection fc =
    (FileConnection)Connector.open("file://localhost/" + currDirName + fileName);

    if (!fc.exists()) {
    throw new IOException("File does not exists");
    }

    InputStream fis = fc.openInputStream();

    byte[] b = new byte[5000];
    //System.out.println("size of image=> "+b.length);
    int length = fis.read(b, 0,5000);
    // int length = fis.read();

    fis.close();
    fc.close();


    img = Image.createImage(b,0,length);
    ImageItem imageItem = new ImageItem(" ",img,ImageItem.LAYOUT_CENTER,"Duke");
    ErrorForm.append(imageItem);

    Display.getDisplay(this).setCurrent(viewForm());
    } catch (Exception e) {
    Alert alert =
    new Alert("Error!",
    "Can not access file " + fileName + " in directory " + currDirName +
    "\nException: " + e.getMessage(), null, AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    }
    }


    Thanks



    Milan

  10. #10
    Registered User
    Join Date
    Aug 2007
    Posts
    7

    Re: File Browsing Problem

    milanexe

    do you find a solution of you problem?
    please tell me how do you soluted?
    qeekey@126.com
    thanks.

  11. #11
    Registered User
    Join Date
    Jul 2007
    Posts
    40

    Re: File Browsing Problem

    hello marwa...

    i also try to do file browser...

    i used carbide c++ 3rd SDK

    can u help me...i urgent..

  12. #12
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,569

    Re: File Browsing Problem

    Quote Originally Posted by jebeng View Post
    hello marwa...

    i also try to do file browser...

    i used carbide c++ 3rd SDK

    can u help me...i urgent..
    If you are trying to use C++, then you are in the wrong forum (this is about Java). Try also the search feature on this site:
    http://discussion.forum.nokia.com/forum/search.php

  13. #13
    Registered User
    Join Date
    Jul 2007
    Posts
    23

    Re: File Browsing Problem

    I am getting this exception now in N75

    can not acces file abc.png in directory c:/data/Images/200709/200709a0
    /Exception: Opening a connection failed: 5

    In Sonyerricson Iam getting restricted api cant acces...

    Whats the problem?

  14. #14
    Registered User
    Join Date
    Oct 2007
    Posts
    13

    Re: File Browsing Problem

    Hello, I'd like to know if I can access SIP Profile configuration files and edit then using FileConnection and a file that contains the available WLAN's and set one as default, I don't even know if those informations are recorded in files and if Java has permission to access them, but this is a way I thought to configure the SIP profile because doesn' t have an API to access it. Thanks in advance for any help.

Similar Threads

  1. Problem with importing a bld.inf file in Carbide C++ express
    By svdwal in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 5
    Last Post: 2006-12-06, 18:43
  2. read string from text file problem
    By sim.sim in forum Symbian
    Replies: 9
    Last Post: 2006-05-24, 07:41
  3. Problem during creating .jar file in JBuilder
    By sachinwarang in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2006-04-17, 15:06
  4. problem while making sis file
    By kunal_the_one in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2004-08-04, 03:36
  5. JAD file problem with 3100/6100
    By rkanhere in forum Mobile Java General
    Replies: 3
    Last Post: 2004-06-24, 19:07

Posting Permissions

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