Skip to content

Commit

Permalink
下载器的网络类型没必要做限制,流量和wifi情况下都可以下载
Browse files Browse the repository at this point in the history
  • Loading branch information
caoyanglee committed Apr 13, 2022
1 parent 0801baf commit 6a9f05e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/src/main/java/com/pmm/silentupdate/core/DownLoadCenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import java.util.*
*/
internal object DownLoadCenter {

private val downloadManager: DownloadManager by lazy { ContextCenter.getAppContext().getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager }
private val downloadManager: DownloadManager by lazy {
ContextCenter.getAppContext().getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
}
private val appUpdateReceiver: AppUpdateReceiver by lazy { AppUpdateReceiver() }
var onDownloadComplete: ((uri: Uri) -> Unit)? = null

Expand All @@ -25,8 +27,8 @@ internal object DownLoadCenter {
val uri = Uri.parse(apkUrl)
loge("url=$apkUrl")
val request = DownloadManager.Request(uri)
//设置在什么网络情况下进行下载
request.setAllowedNetworkTypes(if (isMobileMode) DownloadManager.Request.NETWORK_MOBILE else DownloadManager.Request.NETWORK_WIFI)
//设置在什么网络情况下进行下载 没必要做限制!!!
// request.setAllowedNetworkTypes(if (isMobileMode) DownloadManager.Request.NETWORK_MOBILE else DownloadManager.Request.NETWORK_WIFI)
//设置通知栏标题
request.setNotificationVisibility(if (isMobileMode) DownloadManager.Request.VISIBILITY_VISIBLE else DownloadManager.Request.VISIBILITY_HIDDEN)
request.setTitle(fileName)
Expand Down Expand Up @@ -83,7 +85,7 @@ internal object DownLoadCenter {
val cursor = downloadManager.query(query)
while (cursor.moveToNext()) {
filePath = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))
?: ""
?: ""
}
cursor.close()
return filePath
Expand Down Expand Up @@ -130,8 +132,10 @@ internal object DownLoadCenter {
val address = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))
filePath = address
val status = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))
val size = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
val sizeTotal = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))
val size =
cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
val sizeTotal =
cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))
val map = HashMap<String, String>()
}
cursor.close()
Expand Down

0 comments on commit 6a9f05e

Please sign in to comment.