使用android下载管理器多次下载

时间:2013-11-05 09:48:49

标签: android encryption android-download-manager

我正在使用Android下载管理器从网上下载视频,这已经成功完成,稍后在完成下载后视频将被加密,下载的视频应该被删除。一切正常。但问题是:

我开始下载文件,在完成第一个链接下载视频没有加密并且第二个视频加密成功后立即点击第二个链接。

这是代码

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);

1 个答案:

答案 0 :(得分:0)

这是因为当您在第一个链接完成之前单击第二个链接时,您的enqueue变量将获取第二个链接的下载ID。

我遇到了一个非常类似的问题并解决了它here