我正在尝试使用Android的DownloadManager下载文件,并尝试使用日志语句通过控制台打印下载内容。 虽然文件下载正确,但是我看不到下载进度的日志声明 这是我的代码
private fun downloadPdf(fileName: String?, fileExtension: String?, destinationDirectory: String?, url: String?) {
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val uri = Uri.parse(url)
val request = DownloadManager.Request(uri)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(destinationDirectory, fileName + fileExtension)
val downloadId = downloadManager.enqueue(request)
thread {
val query = DownloadManager.Query()
query.setFilterById(downloadId)
val cursor = downloadManager.query(query)
if(cursor.moveToFirst()){
val sizeIndex = cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)
val downloadedIndex = cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)
val size = cursor.getInt(sizeIndex)
val downloaded = cursor.getInt(downloadedIndex)
val progress: Long
if(size != -1){
progress = downloaded * 100L / size
runOnUiThread {
Log.i("pritishsawantprogress",progress.toString())
}
}
}
}
}
任何帮助将不胜感激
答案 0 :(得分:0)
for const QJsonValue& value : array) {
// here I want to set the value for the 'id' key to 0
addRecording(new Recording(value.toObject()));
}