6

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?

4

3 回答 3

2

从我通过查看源代码可以看出,这是不支持的(尽管它DownloadManager会在自身发生故障后和系统重新启动后自动重试等)。

如果您还没有看到这个这个,看起来那里有一些有用的信息,说明如何使用这些功能自己实现自己的服务。

于 2013-05-23T04:23:29.317 回答
1

我发现了另一个非常令人印象深刻的图书馆

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

例子

于 2014-03-12T08:58:55.437 回答
1

您可以通过将 Downloads.Impl.COLUMN_CONTROL 设置为 Downloads.Impl.CONTROL_PAUSED 来暂停。

并通过设置 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));
}
于 2019-04-16T10:02:44.223 回答