3

I'm using android downloading manager to download video's from web, and this is done successfully and later after completion of download the video as to be encrypted and downloaded video should be deleted. everything works fine. But problem is:

I start download a file, immediately i click on second link now after completion of 1st link download video is not encrypting and 2nd video is encrypting successfully.

Here is the code

dm = (DownloadManager) mContext.getSystemService(Context.DOWNLOAD_SERVICE);
request = new Request(Uri.parse(dataModel.getOtherData()));
File already=new   File(Environment.getExternalStorageDirectory()+"/Access/"+dataModel.getName()+".mp4");
if(!already.exists()){
down.setVisibility(View.GONE);
stp.setVisibility(View.VISIBLE);
request.setDestinationInExternalPublicDir("/vtemp", dataModel.getName()+".mp4");
enqueue = dm.enqueue(request);
}else {
Toast.makeText(mContext, "File Already Exists", Toast.LENGTH_LONG).show();
                }



BroadcastReceiver receiver = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {

// downloadId =
// intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
// Log.v("dekid",""+downloadId);
String action = intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
    downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);
    // downloadId=dm.enqueue(request);
    Query query = new Query();
    query.setFilterById(enqueue);
    Cursor c = dm.query(query);
    if (c.moveToFirst()) {
        // downloadId=c.getColumnIndex(DownloadManager.COLUMN_ID);
        Log.v("downlad ID", "" + downloadId);
        int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
        title=c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
        Log.v("Video Name", ""+title);
        if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
            // request.setShowRunningNotification(false);
            Toast.makeText(context.getApplicationContext(),"Download Successful", Toast.LENGTH_LONG).show();
            String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
            //  Toast.makeText(context, "Download" + uriString,Toast.LENGTH_SHORT);
            Log.v("Encrypt", ""+uriString);     
            stp.setVisibility(View.GONE);
            down.setVisibility(View.VISIBLE);

            encryption task=new encryption();
            task.execute(title);
MAxeF
  • 139
  • 1
  • 10
Pandiri Deepak
  • 176
  • 3
  • 15

1 Answers1

0

It is because when you click on the second link before the first has finished downloading, your enqueue variable will take the download id of the second link.

I had a pretty similar problem and resolved it here

Community
  • 1
  • 1
MAxeF
  • 139
  • 1
  • 10