[英]How can I display a Progress bar while copying files using Apache FileUtils? Android
I am using the Apache commons library for copying files from one directory to another. 我正在使用Apache commons库将文件从一个目录复制到另一个目录。 The issue I am having is that I cannot figure out a way to update a progress bar when copying the file.
我遇到的问题是我无法想出一种在复制文件时更新进度条的方法。 My intial thought was to use a callback, but there is no way to pass in a callback to the copyfile method.
我的初步想法是使用回调,但没有办法将回调传递给copyfile方法。
FileUtils.copyFileToDirectory(fileSrc, fileDest);
I solved my problem as below, May it will be useful to you. 我解决了我的问题如下,可能对你有用。
if (mAdapter != null && mAdapter.getItemCount() > 0) {
final ArrayList<StoryModel> selectedList = mAdapter.getSelectedData();
if (selectedList.size() > 0) {
final ProgressDialog pd = new ProgressDialog(getActivity());
pd.setMessage("Saving Stories....");
pd.show();
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
for (StoryModel imageModel : selectedList) {
String srcFilePath = imageModel.getUrl();
Log.d(TAG, "onOptionsItemSelected: " + srcFilePath);
org.apache.commons.io.FileUtils.copyFileToDirectory(new File(srcFilePath), new File(FileUtils.getAppPath(mContext)));
}
} catch (IOException ignored) {
}
Log.d(TAG, "run: Dismissed....");
pd.dismiss();
}
});
t.start();
} else {
Toast.makeText(mContext, R.string.string_error_select_story_to_download, Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(mContext, R.string.string_error_select_story_to_download, Toast.LENGTH_LONG).show();
}
Thank you :) 谢谢 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.