I am using Download Manager to download file from the internet. The download complete successfully in Android 6, 8.1, but not in Android 9.0
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Downloading...");
request.setTitle(nameOfFile);
request.setMimeType("application/pdf");
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS + "/CPG", nameOfFile);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
queueId = manager.enqueue(request);
This tag worked for me
android:usesCleartextTraffic="true"
Add this tag to the application
<application
android:name=".ApplicationClass"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:usesCleartextTraffic="true"
Solution 2)
Create a XML res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
in your tag Application inside AndroidManifest.xml
android:networkSecurityConfig="@xml/network_security_config"
Download Manger not working in Android Pie 9.0 (Xiaomi mi A2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With