I have a database file which is on the sdcard and now when a new database file is downloaded i need it to overwrite the old one instead of renaming it here is my downloading code. The download code is working perfectly..
public void startDownload() {
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading Database. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.setCancelable(false);
Uri uri=Uri.parse(file_url);
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
File ADirectory = new File(baseDir +"/test");
ADirectory.mkdirs();
lastDownload=
mgr.enqueue(new DownloadManager.Request(uri)
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI |
DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false)
.setTitle(" Database File")
.setDescription("Please wait....test Database downloading.")
.setDestinationInExternalPublicDir("/test", "/testing"));
pDialog.show();
//v.setEnabled(false);
// findViewById(R.id.query).setEnabled(true);
}
when you're submitting the file to the download manager check if the file already exists. then delete it.
private boolean isFileExists(String filename){
File folder1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + filename);
return folder1.exists();
}
private boolean deleteFile( String filename){
File folder1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + filename);
return folder1.delete();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With