我正在使用安卓下载管理器从网站上下载视频,并且已经成功完成下载后,需要对视频进行加密并删除。一切正常运作。但是问题在于:我开始下载一个文件,然后立即单击第二个链接,现在在第一个链接下载完成后,视频没有被加密,而第二个视频却成功加密了。
以下是代码:
以下是代码:
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);