Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 1

Android DownloadManager API not working with mobile Network

Hello,

I use DownloadManager to download a zipped file from a PHP server.

If I use the WIFI network, everything works well (do not download if there is no internet connection).

But if I activate the mobile network of my phone, without having an Internet connection, the download starts and DownloadManager notifies me immediately that the download is completed.

If I look in the destination folder, I can not find anything.
For all that it works well if I have an internet connection (mobile).

Here is my code.
An idea ?

// method to get if phone is connected
private boolean isConnected() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isConnected();
}


//request to DownloadManager
DownloadManager.Request request = new DownloadManager.Request(uri_complete);
            request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE |
                    DownloadManager.Request.NETWORK_WIFI);
request.setAllowedOverRoaming(false); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setDestinationInExternalFilesDir(listener.getContext(), Environment.DIRECTORY_MUSIC + "/audios", diminutif + ".zip"); request.setTitle(nomQassidaFr); downloadId = downloadManager.enqueue(request);


// My PHP file
<?php $path = 'audios'; $file_name = $_GET['file']; if(isset($file_name)) { $fichier = $path . '/' . $file_name . '.zip'; //if(file_exists($fichier)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($fichier)); header("Content-Transfer-Encoding: binary"); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: '.filesize($fichier)); ob_clean(); flush(); readfile($fichier); exit; } ?>