简体   繁体   English

如何在使用Apache FileUtils复制文件时显示进度条? Android的

[英]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.

相关问题 Android:我想提供进度动画(水平)以在android中显示下载进度,而不是使用进度条。 我怎样才能做到这一点? - Android:I want to provide progress animation (horizontal) to display progress of download in android instead of using progress bar. How can i do that? 我的应用程序粘贴文件时如何有效显示进度栏? 安卓系统 - How can I effectively display a progress bar while my app pastes a file? Android 当进度条在 Android 中运行时,如何创建带有移动图像的自定义进度条 - How I can create a custom progress bar with a moving image while the bar is progressing in Android 同步时显示进度条文件的名称 - Display Name of Files In Progress Bar While Syncing 如何在加载活动时显示进度条? 安卓 - How to display progress bar while the activity is loading? Android 如何在检查服务器连接性时显示android进度条 - how to display a android progress bar while checking server connectivity 在 android 中加载网页时使用进度条 - Using a progress Bar while I load a webpage in android Android:如何在将数据加载到WebView时显示进度条? - Android: How can i show progress bar while loading data into WebView? 如何显示Dailymotion云上传的进度栏 - how can i display progress bar for dailymotion cloud uploading 如何在没有额外库的情况下使用android中的xml布局创建弧进度栏? - How can I create arc progress bar using xml layouts in android without extra libraries?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM