novoda / download-manager

A library that handles long-running downloads, handling the network interactions and retrying downloads automatically after failures
Apache License 2.0
483 stars 63 forks source link

unable to save file to particular folder #464

Closed altaf2892 closed 5 years ago

altaf2892 commented 5 years ago

i want to save downloaded file to //String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "App Name"; but i unable to do so.... can u help me?

Mecharyry commented 5 years ago

Is this in relation to v1 or v2?

altaf2892 commented 5 years ago

in v=2.2.0

Mecharyry commented 5 years ago

Thanks @altaf2892. Did you try this using the demo? If so, I would recommend checking using Stetho open a tab in Chrome and use chrome://inspect/#devices, this will allow you to access the db on the device. You can use this to check whether the path is what you expect. I'd then use adb shell if possible to confirm.

It shouldn't have any issues storing the paths as you want, we append a batch identifier to each path and a file identifier. Let me know what the above shows when you have taken a look.

altaf2892 commented 5 years ago

is this lib actually support to save to external path ?

` private void downloadFile(String url, String name, final MessageData messageData) { /* String path = Environment.getExternalStorageDirectory().getPath() + File.separator + "app_Name";

*/ Log.e("CHECK", url + "-" + name); Batch batch = Batch.with(new StorageRoot() { @Override public String path() { return MyApplication.getInstance().getPath(getApplicationContext()); } }, DownloadBatchIdCreator.createSanitizedFrom(messageData.getMessage_id()), name) .downloadFrom(url).withIdentifier(DownloadFileIdCreator.createFrom(messageData.getMessage_id())).apply().build(); manager.download(batch);

    manager.addDownloadBatchCallback(new DownloadBatchStatusCallback() {
        @Override
        public void onUpdate(DownloadBatchStatus downloadBatchStatus) {
            Log.e("CHECK", downloadBatchStatus.storageRoot() + ".");
            switch (downloadBatchStatus.status()) {
                case DOWNLOADED:
                    hashMap.put(downloadBatchStatus.getDownloadBatchId().rawId(), "COMPLETED");
                    chatAdapter.notifyDataSetChanged();
                    break;
                case DOWNLOADING:
                    hashMap.put(downloadBatchStatus.getDownloadBatchId().rawId(), "DOWNLOADING");
                    chatAdapter.notifyDataSetChanged();
                    break;
                case ERROR:
                    hashMap.put(downloadBatchStatus.getDownloadBatchId().rawId(), "ERROR");
                    chatAdapter.notifyDataSetChanged();
                    break;
                case QUEUED:
                    hashMap.put(downloadBatchStatus.getDownloadBatchId().rawId(), "ERROR");
                    chatAdapter.notifyDataSetChanged();
                    break;
                case UNKNOWN:
                    break;
                case DELETED:
                    break;
            }

        }
    });

}

`

Above filewill be stored in package folder like this /data/user/0/pkg/files/appname/176/d0340f19-2d26-4fab-9cdf-4e3002b2af5e.pdf and i want file to be stored here Environment.getExternalStorageDirectory().getPath() + File.separator + "app_Name";

Mecharyry commented 5 years ago

@altaf2892 I think you are confusing some things here. It is not the responsibility of this library to request any necessary permissions required to store to a given directory. If you are storing to this particular apps storage directory then you have that implicitly as the caller. IF you need to store elsewhere then it is the responsibility of the client to gain the appropriate permissions and then pass the storage directory to the download-manager. We would not presume to grant access to external storage for every client of this library, they may not require it.

altaf2892 commented 5 years ago

no u getting me wrong ,i am already handling permission i just want to save file at my desired location that's it..

Mecharyry commented 5 years ago

ok, fair enough. I'm not sure what this is doing as it is hidden in your application:

Batch batch = Batch.with(new StorageRoot() {
@override
public String path() {
return MyApplication.getInstance().getPath(getApplicationContext());
}

But this should be Environment.getExternalStorageDirectory().getPath() + File.separator + "app_Name"; as it is the root that you desire. I've done the same in the demo application and I can see:

screenshot 2018-11-26 at 12 18 27

If it is still failing for you then can you tell me what you see in the logs / in the UI?

Mecharyry commented 5 years ago

Hi @altaf2892 just wanted to check in and see if this resolved your issue?

altaf2892 commented 5 years ago

i will update u soon

Mecharyry commented 5 years ago

@altaf2892 I'm closing this issue due to inactivity. If you wish to raise the bug again with additional information so that we can help you out, that would be fantastic. We aim to get question answered within a few days and I'd rather not leave issues open for long periods of time unnecessarily.