3

I am downloading data from a server using the DownloadManager class in Android. I want to save data in the internal memroy (data/data/mypackage/files/...) instead of the external memory. How to do this?

DownloadManager dm = (DownloadManager) DownloadApplicationActivity.this.getSystemService(Context.DOWNLOAD_SERVICE);
    DownloadManager.Request req = new DownloadManager.Request(Uri.parse(MY_LINK));
    req.setTitle(MY_TITLE)
                    .setDescription("Downloading ....")
                    // download the package to the /sdcard/downlaod path.
                    .setDestinationInExternalPublicDir(
                            Environment.DIRECTORY_DOWNLOADS,
                            MY_PATH);
            long enqueue = dm.enqueue(req);
b.i
  • 1,087
  • 4
  • 22
  • 43

1 Answers1

-1

Try something like this:

// if there is no SD card
        if (Environment.getExternalStorageState() == null) {
            directory = new File(Environment.getDataDirectory()
                    + "/RobotiumTestLog/");
            photoDirectory = new File(Environment.getDataDirectory()
                    + "/Robotium-Screenshots/");

            // if no directory exists, create new directory
            if (!directory.exists()) {
                directory.mkdir();
            }

            // if phone DOES have sd card
        } else if (Environment.getExternalStorageState() != null) {
            // search for directory on SD card
            directory = new File(Environment.getExternalStorageDirectory()
                    + "/RobotiumTestLog/");
            photoDirectory = new File(
                    Environment.getExternalStorageDirectory()
                            + "/Robotium-Screenshots/");

            // if no directory exists, create new directory to store test
            // results
            if (!directory.exists()) {
                directory.mkdir();
            }
        }
BlackHatSamurai
  • 23,275
  • 22
  • 95
  • 156
  • @BlaineOmega: how to use this code? setDestinationInExternalPublicDir(directory, "bla.ext") or something? – RvdK Oct 31 '12 at 09:57
  • No, it is just code within a method. If you want to create a method called `setDestinationInExternalPublicDir` you could, you would just put my code inside the method. – BlackHatSamurai Oct 31 '12 at 22:06