my progress Bar is:
dialog = new ProgressDialog(MainActivity.this);
dialog.setTitle("Copying ... " + fileName );
dialog.setMessage("Copying a file to the internal storage, this can take some time!" );
dialog.setIndeterminate(false);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setCancelable(true);
dialog.setButton(ProgressDialog.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialog.cancel();
CopyTask.this.cancel(true);
}
});
}
What I have tried:
My copy and paste code is..
This methos is call on button click..
public void CopyTask1(View v) {
foldername = "Files1 " + System.currentTimeMillis();
if (adapter == null)
return;
int count = adapter.getCount();
for (int i = 0; i < count; i++) {
copyfiles(i);
}
}
private void copyfiles(int position) {
UsbFile entry = adapter.getItem(position);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(this, R.string.request_write_storage_perm, Toast.LENGTH_LONG).show();
} else
{
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
REQUEST_EXT_STORAGE_WRITE_PERM);
}
return;
}
CopyTaskParam param = new CopyTaskParam();
param.from = entry;
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Files1" + "/" + foldername);
f.mkdirs();
int index = entry.getName().lastIndexOf(".") > 0
? entry.getName().lastIndexOf(".")
: entry.getName().length();
fileName = f.getName();
String prefix = entry.getName().substring(0, index);
String ext = entry.getName().substring(index);
if (prefix.length() < 3)
{
prefix += "pad";
}
try {
param.to = File.createTempFile(prefix, ext, f);
} catch (IOException e) {
e.printStackTrace();
}
new CopyTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, param);
}