By Julien Quiévreux
20th May 2011.
12:54
give sources from the screenshot would be a good idea
0
0
This is the first in a series of tips that supplement the Xperia™ game developer recommendations. This first tip expands on recommendation AP13: A download should automatically resume if the connection fails.
The Xperia™ game developer recommendations offers guidance in developing games for Xperia™ devices such as Xperia™ PLAY. The tips in this series provide additional information about some of the significant recommendations in that document. Each tip provides the following information:
Recommendation
A download should automatically resume if the connection fails.
Background
If a user is trying to download a game, and the device’s connection fails, the download should resume when the connection is restored. This saves the user from having to repeat the download request.
Special considerations
If your download uses the HTTP protocol, you should take advantage of Android’s Download Manager to automatically retry a download if the connection fails.
The DownloadManager is a system service designed to handle long-running HTTP downloads. It runs the download in the background. If a failure occurs, such as one resulting from a broken connection or a system reboot, the DownloadManager saves the state of the download. After the failure is corrected, for instance, the connection is reestablished, the DownLoadManager attempts to resume the download at the point the download stopped.
In order for the Download Manager to resume the download, the server supplying the download needs to support the HTTP 206 status code and the HTTP ETag response header field. The DownloadManager uses the HTTP 206 status code and the ETag header to manage state for the download. It keeps the ETag and the count of downloaded bytes in a database. This information enables the DownloadManager to determine the point at which to resume the download.
The DownloadManager only supports HTTP downloads. If you use another protocol for the download, such as HTTPS or FTP, you should implement a retry mechanism.
Examples
Here is a code snippet that illustrates how to use the DownLoadManager to manage a download.
//import the Download Manager
import android.app.DownloadManager;
//get instance of the DownloadManager
DownloadManager downloadManager = (DownloadManager)
getSystemService(Context.DOWNLOAD_SERVICE);
//set download URI
Uri downloadUri = Uri.parse(downloadUriString);
//setup download request
DownloadManager.Request downloadRequest = new DownloadManager.Request(downloadUri);
downloadRequest.setDestinationUri(mDestinationUri);
//set allowed network types
downloadRequest.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
//set title for the download to appear in the notification area
downloadRequest.setTitle(mFileName);
//set description for the download to appear in the notification area
downloadRequest.setDescription(getText(R.string.downloadDesc).toString());
//initiate download
mDownloadId = downloadManager.enqueue(downloadRequest);
More information
By Julien Quiévreux
20th May 2011.
12:54
give sources from the screenshot would be a good idea
0
0
By Edward Ort
26th May 2011.
19:22
@Julien: See my previous response.
0
0
By Julien Quiévreux
20th May 2011.
12:55
give sources for the screenshot would be a good idea
0
0
By Edward Ort
26th May 2011.
19:17
@Julien: The source code for the app shown in the screenshot is available at http://developer.sonyericsson.com/wportal/devworld/downloads/download/downloadexampleapp?cc=gb&lc=en
0
0
From Game developer tip 3: Installing large APK files to the SD card — Developer World
29th August 2011.
14:35
[...] Read our first game developer tip on automatically resuming downloads.>>> [...]
0
0
Sort by