尝试像这样使用DownloadManager
DownloadManager.Request request = new DownloadManager.Request(uri)
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE)
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI)
.setAllowedOverRoaming(true)
.setDestinationInExternalFilesDir(this, null,String.valueOf(mPathAndFolder))
.setVisibleInDownloadsUi(false)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
long downloadID = downloadManager.enqueue(request);
在 Android Manifest 中添加了以下权限
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>
在运行时出现以下错误
java.lang.NoSuchMethodError: android.app.DownloadManager$Request.setNotificationVisibility
为什么会出现这个错误?如何使下载管理器工作?