gpt4 book ai didi

android - java.lang.NoSuchMethodError : android. app.DownloadManager$Request.setNotificationVisibility 错误

转载 作者:行者123 更新时间:2023-11-29 16:08:22 29 4
gpt4 key购买 nike

尝试使用 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

为什么会出现这个错误?如何使 DownloadManager 工作?

最佳答案

Do I need to use two separate DownloadManager.Request one for API 9 and another for API 11?

不,但是您确实需要使用 Java 保护 block :

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);

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) {
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
}

而且,您将不得不接受这样一个事实,即您的下载对于 API 级别 9 和 10 的设备是可见的。

关于android - java.lang.NoSuchMethodError : android. app.DownloadManager$Request.setNotificationVisibility 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15887830/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com