问题
I Set this in download manager but it does not work even in WIFI:
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_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.NETWORK_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