
|
September 2005 |
|
|
PDA optional packages (JSR 75) gives developers access to two major areas that were previously unavailable. These are the PIM API which gives access to the Personal Information Management (PIM) database including to-do lists, calendars and contact data. The second optional package is the FileConnection API that gives access to the mobile phone's file system including removable storage media like Memory Sticks. Currently Java This article is divided into two sections: the first part (this article) focuses on the FileConnection API and includes an example to download, and the second part (to follow) describes the PIM API. Download FileConnection example>> Dealing with restricted APIs When distributing software that uses these kind of restricted APIs and the MIDlet is signed, it is crucial for usability to instruct the user how to set the blanket option so there is no need to click through the permission dialogs every time the MIDlet is accessing a restricted API. This can also be set in the permissions menu. Navigate to the permissions menu from marking your MIDlet and choose the "more" option (left soft button). From the more menu, choose "permissions", from that menu different permissions can be configured and if your MIDlet is signed you can set the blanket option for the desired functionality. Permissions Two permissions are defined for the Fileconnection API:
The read permission is used when a file is open in read mode or if an InputStream is opened from a FileConnection object. The write permission is used to open files in write mode or if an OutputStream is opened from a FileConnection. It is also used when invoking other write operations like delete or rename. If you are not granted the permission to access the restricted API, a SecurityException is thrown and it is important to manage these situations in your MIDlet. Like all kinds of I/O operations, it is highly recommended that you execute your file system I/O operations in a thread of their own to prevent any deadlocks. Sony Ericsson specifics:
You can read about all the specifics in the Sony Ericsson Java ME Platform Developers' Guidelines, page 42>> System properties: Classes and interfaces in the FileConnection API
Using the FileConnection API To create a FileConnection, use the Connector factory's open method which returns a Connection:
Valid URLs:
So when accessing the other directory in the internal memory, create a FileConnection object using the URL below: Since the mode parameter in Connector.open() method is not supported, both the read and write permissions are set when creating a FileConnection object. When creating a FileConnection, the actual file or directory that the URL is pointing to doesn't have to exist, so opening a file/directory and creating a new file/directory is very similar. This is necessary when creating files and directories. Remember to close the FileConnection object when you are done using it: A FileConnection that is pointing to a non-existent file will not be able to perform any file or directory specific operations. For example, if you are trying to open an InputStream or an OutPutStream, a java.io.IOException will be thrown. The only difference is when the FileConnection is open the method create() or mkdir() is invoked to create the file or directory on the file system. You can always check if the file/directory exists: If it doesn't exist, create a new file: or create a directory: To delete a file or a directory: To list the content of a directory that your FileConnection is pointing to: This method returns an enumeration of all directories and files that are present in the directory. Directories are denoted with a trailing slash "/" in their returned name. There is a second version of the list method that enables you to sort the content with a filter: This methods return the content that is passing the filter, the filter could be "*.mp3" for only listing files that ends with .mp3. Use the attribute includeHidden to indicate whether files marked as hidden should be included or not in the list of files and directories returned. These methods return folders and files in a random order so you need to sort them manually. The FileSystemRegistry has the static method listRoots() to list the available and supported mounted roots on the device. The list is returned as an Enumeration : File I/O Or you can use the DataOutputStream to write primitive Java datatypes to a file: To read from a file you get the InputStream or a DataInputStream from a FileConnection object that is pointing to the existing file: File and directory information boolean canRead() - Is the file/directory readable? boolean canWrite() - Is the file/directory writable? long directorySize(boolean includeSubDirs) - Returns the size of all the files in bytes in the directory. If the includeSubDirs is true the size of all the sub-directories are included. long fileSize() - Returns the size of the file in bytes long lastModified() - Returns the date when the file/directory was last modified Play media files instantly using progressive download on the W600 Progressive download is a technique used to play media while the media is still being downloaded to the player (you may have noticed this when looking at video clips on the internet). The video is being played while the player is still downloading and buffering the content. Before the implementation of the progressive download, the entire media file was loaded into the memory before it was played, resulting in long waiting times from the media being loaded to it actually was played (more obvious when the media file was large). The benefit of this is obvious when playing large media files and especially when using play list functionality. To use progressive download you need to create a player using the file scheme like this:
More information:
| |
Copyright © 2001 - 2009 Sony Ericsson Mobile Communications AB. All Rights Reserved.