3

我正在使用DownloadManagerAndroid 中的类从服务器下载数据。我想将数据保存在内部存储器(data/data/mypackage/files/...)而不是外部存储器中。这个怎么做?

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);
4

1 回答 1

-1

尝试这样的事情:

// 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();
            }
        }
于 2012-07-10T17:21:10.410 回答