Pause android DownloadManager

左心房为你撑大大i 提交于 2019-12-10 13:06:03

问题


In my application I'm downloading movies from the server. Some of them are very big (4gb or more). I tried to implement my own download manager as a service and it was not quit good. On some devices the app just crashes into itself without any notice, and overall the download seems to be too slowly.

So, I wanted to use Android's default DownloadManager, but my only problem is that I can't pause/resume it.

Is there a way to implement that?


回答1:


From what I can tell by looking at the source code, this isn't supported (although the DownloadManager will automatically retry after failures on its own and after system reboots, etc.).

If you haven't seen this or this already, it looks like there is some useful information there on how to implement your own service yourself with these capabilities.




回答2:


I found another very impressive library

https://github.com/Trinea/android-common




回答3:


You can pause by set the Downloads.Impl.COLUMN_CONTROL to Downloads.Impl.CONTROL_PAUSED.

And resume by set the Downloads.Impl.COLUMN_CONTROL, Downloads.Impl.CONTROL_RUN

    public void pauseOrResumeDownload(boolean pause, long... ids) {
    ContentValues values = new ContentValues();
    if (pause) {
        values.put(Downloads.Impl.COLUMN_CONTROL, Downloads.Impl.CONTROL_PAUSED);
    } else {
        values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_PENDING);
        values.put(Downloads.Impl.COLUMN_CONTROL, Downloads.Impl.CONTROL_RUN);
    }
    mResolver.update(mBaseUri, values, getWhereClauseForIds(ids), getWhereArgsForIds(ids));
}


来源:https://stackoverflow.com/questions/13330015/pause-android-downloadmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!