我想从Dropbox下载特定图片,然后保存到SD卡。
按钮后单击文件夹在Sdcard中创建,图像也保存在该文件夹中。
问题: 图像尺寸显示为 0 Kb
点击图片显示黑屏。
请帮我解决这个问题
按钮点击下载图片
Download.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
File file1 = new File("/Photos/Picture_2015-07-06_13-41-04.png");//A specific Picture from Dropbox.
downloadDropboxFile(file1);
}});
private boolean downloadDropboxFile(File fileSelected) {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MYfolder";
File dir = new File(path);
if (!dir.exists())
dir.mkdirs();
try {
File localFile = new File(dir + "/" + fileSelected.getName());
if (!localFile.exists())
{
localFile.createNewFile();
copy(fileSelected, localFile);
} else {
//showFileExitsDialog(fileSelected, localFile);
}
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
private void copy(final File fileSelected, final File localFile) {
final ProgressDialog pd = ProgressDialog.show(DBRoulette.this,
"Downloading...", "Please wait...");
new Thread(new Runnable() {
@Override
public void run() {
BufferedInputStream br = null;
BufferedOutputStream bw = null;
DropboxInputStream fd;
try {
fd = mApi.getFileStream(fileSelected.getPath(),localFile.getPath());
br = new BufferedInputStream(fd);
bw = new BufferedOutputStream(new FileOutputStream(localFile));
byte[] buffer = new byte[4096];
int read;
while (true) {
read = br.read(buffer);
if (read <= 0) {
break;
}
bw.write(buffer, 0, read);
}
pd.dismiss();
Message message = new Message();
message.obj = localFile.getAbsolutePath();
message.what = 1;
//mHandler.sendMessage(message);
} catch (DropboxException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bw != null) {
try {
bw.close();
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}).start();
}