Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);

//        Toast.makeText(MainActivity.this, "files" + adapter.getCount(), Toast.LENGTH_SHORT).show();


        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);
        // prefix must be at least 3 characters
        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);


    }
Posted
Updated 22-Jan-18 23:19pm
Comments
David Crow 23-Jan-18 8:43am    
You should refrain from calling checkSelfPermission(), shouldShowRequestPermissionRationale(), and requestPermissions() each time through the loop. Call those once before entering the loop.

That aside, what exactly is the problem?

1 solution

 
Share this answer
 
Comments
David Crow 23-Jan-18 8:45am    
How exactly is a C# desktop application a solution to his Android problem? This is not a solution in the slightest sense of the word.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900