Android 8.0 DownloadManager not working in MOBILE DATA

馋奶兔 提交于 2019-12-08 00:51:54

问题


I Set this in download manager but it does not work even in WIFI:

request.setAllowedNetworkTypes(DownloadManager.Request.NETWO‌​RK_WIFI | DownloadManager.Request.NETWORK_MOBILE)

And This code below can work: BUT ONLY IN WIFI MODE so that It can NOT download using MOBILE data

request.setAllowedNetworkTypes(DownloadManager.Request.NETWO‌​RK_WIFI) 

Is this a bug in Download Manager?


回答1:


I have similar problem. But removing line of setAllowedNetworkTypes doesn't work.

My problem can be reproduced on 8.1 emulator. But it works well on a real device.

My solution is to setAllowedOverRoaming(false). I don't know why.




回答2:


Check network availability, especially the wifi/mobile signal icon on statusbar. If a little cross is there, the system will treat it as no net and will not proceed downloading(I've encountered this recently).




回答3:


As the developer says:

setAllowedNetworkTypes

added in API level 9
public DownloadManager.Request setAllowedNetworkTypes (int flags)
Restrict the types of networks over which this download may proceed. By default, all network types are allowed. Consider using setAllowedOverMetered(boolean) instead, since it's more flexible.

So just remove this line will work.




回答4:


Change Android Manifest permission external write permission like below,

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace"/>


来源:https://stackoverflow.com/questions/48958804/android-8-0-downloadmanager-not-working-in-mobile-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!