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 に答える