Skip to main content

acess photos folder with lwit

2 replies [Last post]
geomatical04
Offline
Joined: 2009-05-15

Hello,

Normally, i use the path "fileconn.dir.photos" but in lwuit it does not work! any ideas? Thank you

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
geomatical04
Offline
Joined: 2009-05-15

ok My fault :)

In order to access the file system you can not act directly but you should use File Connection Api. This is the code :
--------------------------------------------------------
[code]
import com.sun.lwuit.*;
import com.sun.lwuit.events.*;
import javax.microedition.midlet.*;
import javax.microedition.io.file.FileConnection;
import javax.microedition.io.Connector;
import java.io.IOException;
import java.io.InputStream;

public class HelloLWUITMidlet extends MIDlet implements ActionListener {
public Image image = null;
public void startApp() {
Display.init(this);

Form f = new Form("Hello, LWUIT!");
Label label = new Label("Baldy");
f.addComponent(label);

image = readFile("file:///root1/foo.png");
Label pictureLabel = new Label(image);
f.addComponent(pictureLabel);

f.show();

Command exitCommand = new Command("Exit");
f.addCommand(exitCommand);
f.setCommandListener(this);
}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void actionPerformed(ActionEvent ae) {
notifyDestroyed();
}

public Image readFile(String path) {
try {
FileConnection fc = (FileConnection)Connector.open(path, Connector.READ);
if(!fc.exists()) {
System.out.println("File doesn't exist!");
}
else {
int size = (int)fc.fileSize();
InputStream is = fc.openInputStream();
byte bytes[] = new byte[size];
is.read(bytes, 0, size);
image = Image.createImage(bytes, 0, size);
}

} catch (IOException ioe) {
System.out.println("IOException: "+ioe.getMessage());
} catch (IllegalArgumentException iae) {
System.out.println("IllegalArgumentException: "+iae.getMessage());
}
return image;
}

}
[/code]

Message was edited by: geomatical04

thisisnotme
Offline
Joined: 2009-01-19

This doesn't have anything to do with LWUIT. Either your code to get the system property has changed, or you have changed your phone?

The Sony Ericson Developper Guidelines Says This:

Note: Property retrieval behaviour differs slightly between some early JP-6 phone models and other
phones, due to changes in the fileconn property syntax. Null may be returned when using the above
syntax with some early JP-6 phones. The following code could be used to provide a generic means to
address this behaviour difference:
public String getProperty(String param)
{
int index = param.indexOf(".");
String extension = param.substring(index,param.length());
String value = System.getProperty("fileconn" + extension);
return value != null ? value : System.getProperty("filconn" + extension);
}