我正在使用图像库中的文件选择器,这在我的9850操作系统7中工作正常,但是当我使用相同的应用程序部署到9780 Os6 Bold设备时,它无效。
public final class MyScreen extends MainScreen implements FieldChangeListener
{
Bitmap bitmap;
ButtonField click;
BitmapField bitmapField;
public MyScreen()
{
setTitle("FilePicker Screen");
createGUI();
}
private void createGUI()
{
add(new LabelField("Click to select the image", Field.FIELD_HCENTER));
click=new ButtonField("Click");
click.setChangeListener(this);
add(click);
bitmapField=new BitmapField();
add(bitmapField);
}
private Bitmap getTheImage(String url)
{
Bitmap bitmap=null,scaleBitmap=null;
InputStream inputStream=null;
FileConnection fileConnection=null;
try
{
fileConnection=(FileConnection) Connector.open(url);
inputStream=fileConnection.openInputStream();
byte[] data=new byte[(int)fileConnection.fileSize()];
data=IOUtilities.streamToBytes(inputStream);
inputStream.close();
fileConnection.close();
bitmap=Bitmap.createBitmapFromBytes(data,0,data.length,1);
scaleBitmap=new Bitmap(250, 250);
bitmap.scaleInto(scaleBitmap, Bitmap.FILTER_LANCZOS);
}
catch (Exception e)
{
try
{
if(inputStream!=null)
{
inputStream.close();
}
if(fileConnection!=null)
{
fileConnection.close();
}
}
catch (Exception exp)
{
}
scaleBitmap=Bitmap.getBitmapResource("noimage.png");//Your known Image;
}
return scaleBitmap;
}
public void fieldChanged(Field field, int context)
{
if(field==click)
{
try
{
FilePicker filePicker;
filePicker=FilePicker.getInstance();
filePicker.setPath("file:///store/home/user/pictures/");
filePicker.setListener(new Listener()
{
public void selectionDone(String path)
{
bitmapField.setBitmap(getTheImage(path));
}
});
filePicker.show();//it show what ever you select.
}
catch (Exception e)
{
}
}
}
}
我在这里做错了什么?
请帮帮我。