Skip to content

shannah/cn1-filechooser

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
bin
 
 
 
 
 
 

Filechooser for Codename One

Supported Platforms:

  • Javascript
  • iOS
  • Android
  • Simulator (JavaSE)

Installation

For instructions on installing cn1libs, see https://www.codenameone.com/blog/automatically-install-update-distribute-cn1libs-extensions.html[this tutorial].

Alternate Maven Installation

If your project uses Maven, the above installation instructions will still work, but you can alternately simply add the Maven dependency to your common/pom.xml file:

<dependency>
  <groupId>com.codenameone</groupId>
  <artifactId>filechooser-lib</artifactId>
  <version>1.0</version>
  <type>pom</type>
</dependency>

IMPORTANT: If deploying to iOS, you'll need to make sure that your App ID includes iCloud support, and you must associate with at least one iCloud container. See iOS setup instructions here

Code Sample:

if (FileChooser.isAvailable()) {
    FileChooser.showOpenDialog(".xls, .csv, text/plain", e2-> {
        String file = (String)e2.getSource();
        if (file == null) {
            hi.add("No file was selected");
            hi.revalidate();
        } else {
           String extension = null;
           if (file.lastIndexOf(".") > 0) {
               extension = file.substring(file.lastIndexOf(".")+1);
           }
           if ("txt".equals(extension)) {
               FileSystemStorage fs = FileSystemStorage.getInstance();
               try {
                   InputStream fis = fs.openInputStream(file);
                   hi.addComponent(new SpanLabel(Util.readToString(fis)));
               } catch (Exception ex) {
                   Log.e(ex);
               }
           } else {
               hi.add("Selected file "+file);
           }
        }
        hi.revalidate();
    });
}

Troubleshooting:

See Troubleshooting wiki page for common errors related to this library and how to fix them.

Other Useful Links

Credits