我正在使用 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);