val downloadManager = getSystemService(DOWNLOAD_SERVICE) as DownloadManager
val request = DownloadManager.Request(Uri.parse("https://xxx.xx"))
val filename = "update" + System.currentTimeMillis()
val dir: String = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString() + "/"
val file = File("$dir$filename.apk")
request.setTitle("dm-test")
request.setDescription("downing...")
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setMimeType("application/vnd.android.package-archive")
request.setDestinationUri(Uri.fromFile(file))
downloadManager.enqueue(request)
这段代码在android api中工作<33是没有问题的,在android api=33通知没有工作
您可以尝试一次
request.setVisibleInDownloadsUi(true(;
也许它可以工作
如果你的应用程序目标操作系统是android 13,你需要向用户请求通知权限。
你可以参考下面的链接,
https://developer.android.com/develop/ui/views/notifications/notification-permission