Windows Phone official example: Background Transfer Service Sample (background transmission)

Source: Internet
Author: User

This example shows how to use the background transmission service to download files in the background, even if the application is no longer running in the foreground.

Upload and download using backgroundtransferrequest

// Create the new transfer request, passing in the URI of the file to // be transferred.BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);// Set the transfer method. GET and POST are supported.transferRequest.Method = "GET";

You can use transferpreferences to set whether to use WiFi for download and whether to use it for download during charging.

 // If the WiFi-only checkbox is not checked, then set the TransferPreferences            // to allow transfers over a cellular connection.            if (wifiOnlyCheckbox.IsChecked == false)            {                transferRequest.TransferPreferences = TransferPreferences.AllowCellular;            }            if (externalPowerOnlyCheckbox.IsChecked == false)            {                transferRequest.TransferPreferences = TransferPreferences.AllowBattery;            }            if (wifiOnlyCheckbox.IsChecked == false && externalPowerOnlyCheckbox.IsChecked == false)            {                transferRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;            }

 

Use independent storage to keep files

// In independent storage, determine whether a file already exists. If yes, delete using (isolatedstoragefile isostore = isolatedstoragefile. getuserstoreforapplication () {string filename = downloadfile; If (isostore. fileexists (filename) {isostore. deletefile (filename );}}

Class backgroundtransferrequest attributes:

Transferstatus transmission status

Totalbytestoreceive File Size

Bytesreceived size of the received File

 

Download Code:

Http://code.msdn.microsoft.com/wpapps/Background-Transfer-ce07e86f

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.