i just want to know what is the current user folder of the photos gallery whether its on SD or internal mem.
My impression is that the confusion, comes from the fact that each platform (Series 40/Symbian) has a different absolute path to the Gallery directory. That's why one can use the System property "fileconn.dir.photo" in order to use the same code for cross platform development.
I feel like nokia made an error in their implementation and the system property "fileconn.dir.photos" should have return full path to the current phots gallery folder
The fileconn.dir.photos returns the URL locator that one needs in order to open a file connection to the root of the gallery directory. In the case of SDK 2.0, this evaluates to
file:///C:/predefgallery/predefphotos/
You could easy copy an image, say "sample.jpg" to the following path:
C:\Nokia\Devices\Nokia_SDK_2_0_Java\bin\storage\2000\C\predefgallery\predefphotos\
then launch the SDK 2.0 emulator. You should be able to see the picture you just copied, by selecting the gallery app from the emulator.
Alternatively, if you need to read/open a picture stored in the gallery with a Java application, you could again copy the file sample.jpg to the same directory (C:\Nokia\Devices\Nokia_SDK_2_0_Java\bin\storage\2000\C\predefgallery\predefphotos\) and use this code:
Main MIDlet
Code:
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
public class ReadMIDlet
extends MIDlet implements CommandListener {
private Form form;
private Command exitCommand;
private Command openImage;
public void startApp() {
form = new Form("ReadMIDlet");
exitCommand = new Command("Exit", Command.EXIT, 1);
openImage = new Command("Open", Command.OK, 2);
form.addCommand(exitCommand);
form.addCommand(openImage);
form.setCommandListener(this);
Display.getDisplay(this).setCurrent(form);
Display.getDisplay(this).setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c == openImage) {
DirectCanvas canvas = new DirectCanvas();
canvas.openImage();
Display.getDisplay(this).setCurrent(canvas);
}
}
}
Supportive Canvas class
Code:
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import com.sun.lwuit.EncodedImage;
public class DirectCanvas extends Canvas{
String path;
Image img;
DirectCanvas() {
path = System.getProperty("fileconn.dir.photos") + "sample.jpg";
System.out.println(path);
}
protected void paint(Graphics g) {
g.drawImage(img, 0, 0, Graphics.TOP | Graphics.LEFT);
}
public void openImage() {
try {
FileConnection fc = (FileConnection)Connector.open(path, Connector.READ);
if(!fc.exists()) {
System.out.println("File not found!\n");
}
else
{
int size = (int)fc.fileSize();
InputStream is = fc.openInputStream();
byte bytes[] = new byte[size];
is.read(bytes, 0, size);
img = Image.createImage(bytes, 0, size);
repaint();
is.close();
fc.close();
System.out.println("Done");
}
} catch (Exception e) {
System.out.println("Exception: "+e.getMessage() + "\n");
}
}
}