File stuck in pending until WiFi is turned on

74 Views Asked by At

I'm using Download Manager to download a file Ton an Android 10 device that is connected to a private APN on cellular network which leads to a private server. *The server is not reachable from regular internet.

The request looks like this:

DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
request.setDestinationUri(Uri.fromFile(getFile()));
request.setAllowedOverMetered(true);
request.setAllowedOverRoaming(true);
request.setTitle(mContext.getString(R.string.title));
request.setDescription(mName);

Saving the file into File file = new File(Environment.getExternalStorageDirectory(), "Download");

Manifest is configured with necessary permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

When pushing a file through the Download Manager code, I can see the file is on queue, with status: 1 ("PENDING"). When I turn on WiFi, the download notification appears and the file fails to download (as it is not reachable from the internet). There is no error in Logcat logs.

Tests I've done:

  1. Checked downloading the file directly from a browser and it works.
  2. Tried downloading a file from the internet using the same code, both over WiFi and regular Cellular and it works.
  3. Installed the same code on Android 12 and Android 13 device - same thing.

How can I make Download Manager work without the internet connectivity it probably requires?

1

There are 1 best solutions below

1
Nikola Despotoski On

Download request fails with a reason code for the error. The reason is stored in DownloadManager.COLUMN_REASON and if it is http error in then it is stored like a non 200 integer, in your case it has to be PAUSED_WAITING_FOR_NETWORK code.