简体   繁体   中英

Download .db file with Android DownloadManager

I am attempting to download a .db file from my organization's website within an Android application and have encountered difficulties. It says the download is unsuccessful.

Here is the code that handles the download:

package midamcorp.com.burgerkingapp;

import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

public class downloadReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context c, Intent i) {
   File localDBFile = new File(c.getFilesDir(), "bk.db");

        try {

                    DownloadManager manager = (DownloadManager) c.getSystemService(Context.DOWNLOAD_SERVICE);


            Uri uriTest = Uri.parse("http://www.midamcorp.com/bk.db");

                    DownloadManager.Request request = new DownloadManager.Request(uriTest);


         if (localDBFile.exists()) {
                    localDBFile.delete();
                 }

                    manager.enqueue(request);

               //  }


  }
         catch(Exception ex) {
            Log.e("Error", ex.getMessage());
        }
}

        }

Furthermore, when I navigate to this file in my browser, I receive a 404 error; however, I know the path is correct. I have a feeling it has to do with the file extension (.db). How can I fix this?

Thanks!

Furthermore, when I navigate to this file in my browser, I receive a 404 error; however, I know the path is correct

It is not correct, because you are getting 404. URL is invalid or for any other reasons you are not able to reach it, and so is DownloadManager

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM