问题
I am working on File picker from image gallery thats working fine in my 9850 os 7 but when same app if I am deployin to 9780 Os6 Bold device it's not working.
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)
{
}
}
}
}
What I am doing wrong here?
Please help me.
来源:https://stackoverflow.com/questions/21203086/unexpected-behavior-of-file-picker-blackberry