Does network.download() work on Android?

I’ve tried it out already, and it works on my iOS builds but not on my Android ones.

I’m using it to grab an image + a string from my server that will allow me to keep my “coming soon” page up to date, but on Android it never works. I thought maybe it was taking too long to download the images, but they’re small files.

When I use the following I get the error message appearing straight away.:

local function imageListener(event) if ( event.isError ) then errStr = display.newtext ("Network image error - download failed", ....... ) end end
I am using the following to grab the image and save it to the temp directory:

network.download( "http://mywebsite/folder/image.jpg", "GET", imageListener, "tempimage.jpg", system.TemporaryDirectory )

Have I done something wrong? It seems strange that it work on iOS with no problems, and yet the Android version makes no attempts to download the image. [import]uid: 84115 topic_id: 30153 reply_id: 330153[/import]

The [lua]network.download()[/lua] function does work on Android. Our sample app “Networking/AsynchImageDownload” that is included with the Corona SDK proves it.

I’m thinking that your server requires some HTTP header to be set. The Apple operating systems automatically add some headers if you don’t provide them, such as…
[lua] ACCEPT: */*
ACCEPT-LANGUAGE: en-us
ACCEPT-ENCODING: gzip, deflate[/lua]

The Android and Windows operating system do not automatically add headers. So, I’m thinking that you should find out what headers are required by your server and add them… such as the ones mentioned above.

Also, and this may sound like a dumb question, but are you sure that your Android device has Internet access and can reach the web server? Try accessing your web server via the standard Android browser app. [import]uid: 32256 topic_id: 30153 reply_id: 120804[/import]

OK thanks, I’ll give that a try and report back if it works.
Also, you’re question wasn’t quite so dumb. The very first time I tried the phone was in airplane mode :slight_smile: [import]uid: 84115 topic_id: 30153 reply_id: 120831[/import]

Try DocumentsDirectory instead of Temp - I also had problems with network.download trying to save to Temp directory. [import]uid: 41153 topic_id: 30153 reply_id: 120832[/import]

OK so I tried out the “Networking/AsynchImageDownload” sample app on my device (HTC Sensation), but switched the ‘hello corona’ image for the image on my server. The app found the image and displayed it on screen, but it was very slow compared to the iOS version.
It took around 10 seconds for the images to appear. Now admittedly it’s a big image (2048 * 1536) as it’s used for the ipad3 and I intend to put multiple sized versions on the server, is that likely to be the only reason it’s slow? [import]uid: 84115 topic_id: 30153 reply_id: 120981[/import]

Actually, the download speed can vary wildly between different Android devices. I suspect the biggest performance hit is actually file IO. Some Android devices have hideously slow file read/write speeds. The most famous one (for being slow) is the Samsung Galaxy S. That device is so famously slow, that people “root” it in and install an app named “One Click Lag Fix” to work-around the slow IO speeds.

In any case, I suspect the above to be the case. I would recommend that you test your download on another Android device and compare download speeds. Also, if your app is installed on external storage, particularly an SD card, then that would probably slow things down further. [import]uid: 32256 topic_id: 30153 reply_id: 121055[/import]

The [lua]network.download()[/lua] function does work on Android. Our sample app “Networking/AsynchImageDownload” that is included with the Corona SDK proves it.

I’m thinking that your server requires some HTTP header to be set. The Apple operating systems automatically add some headers if you don’t provide them, such as…
[lua] ACCEPT: */*
ACCEPT-LANGUAGE: en-us
ACCEPT-ENCODING: gzip, deflate[/lua]

The Android and Windows operating system do not automatically add headers. So, I’m thinking that you should find out what headers are required by your server and add them… such as the ones mentioned above.

Also, and this may sound like a dumb question, but are you sure that your Android device has Internet access and can reach the web server? Try accessing your web server via the standard Android browser app. [import]uid: 32256 topic_id: 30153 reply_id: 120804[/import]

OK thanks, I’ll give that a try and report back if it works.
Also, you’re question wasn’t quite so dumb. The very first time I tried the phone was in airplane mode :slight_smile: [import]uid: 84115 topic_id: 30153 reply_id: 120831[/import]

Try DocumentsDirectory instead of Temp - I also had problems with network.download trying to save to Temp directory. [import]uid: 41153 topic_id: 30153 reply_id: 120832[/import]

OK so I tried out the “Networking/AsynchImageDownload” sample app on my device (HTC Sensation), but switched the ‘hello corona’ image for the image on my server. The app found the image and displayed it on screen, but it was very slow compared to the iOS version.
It took around 10 seconds for the images to appear. Now admittedly it’s a big image (2048 * 1536) as it’s used for the ipad3 and I intend to put multiple sized versions on the server, is that likely to be the only reason it’s slow? [import]uid: 84115 topic_id: 30153 reply_id: 120981[/import]

Deleting these 2 posts as I had made a mistake. [import]uid: 84115 topic_id: 30153 reply_id: 121698[/import]

Deleted
[import]uid: 84115 topic_id: 30153 reply_id: 121702[/import]

Actually, the download speed can vary wildly between different Android devices. I suspect the biggest performance hit is actually file IO. Some Android devices have hideously slow file read/write speeds. The most famous one (for being slow) is the Samsung Galaxy S. That device is so famously slow, that people “root” it in and install an app named “One Click Lag Fix” to work-around the slow IO speeds.

In any case, I suspect the above to be the case. I would recommend that you test your download on another Android device and compare download speeds. Also, if your app is installed on external storage, particularly an SD card, then that would probably slow things down further. [import]uid: 32256 topic_id: 30153 reply_id: 121055[/import]

Deleting these 2 posts as I had made a mistake. [import]uid: 84115 topic_id: 30153 reply_id: 121698[/import]

Deleted
[import]uid: 84115 topic_id: 30153 reply_id: 121702[/import]