Question

I'm trying to use LiveConnectClient.BackgroundUploadAsync in wp8, to upload copy of some data.

Her is my code:

var progress = new Progress<LiveOperationProgress>();
progress.ProgressChanged += progress_ProgressChanged;
try
{
   LiveOperationResult res = 
        await liveClient.BackgroundUploadAsync(folderID,
              new Uri(@"\shared\transfers\" + backupFile.Name, UriKind.Relative),
              OverwriteOption.Overwrite, new System.Threading.CancellationTokenSource().Token, progress);
   dynamic result = res.Result;
   fileID = result.id;
}
catch (Exception ex)
{
    System.Diagnostics.Debug.WriteLine(ex.Message);
    progress.ProgressChanged -= progress_ProgressChanged;
}

It's working fine on emulator, but when I tried it on the phone its working only when the phone connected to pc by usb , the phone connected to wifi.

Was it helpful?

Solution

You are facing 'problems' with BackgroundTransfer Policies.

The operating system enforces a number of restrictions on background transfers related to file size, connection speeds, and device resources.

Which means that when you download/upload larger files you need to change TransferPreferences - for example if you want to upload a file larger than 100 Mb you will be able to do that, but only via WiFi and while Phone is connected to external power source.

In your App you should check for WiFi connection and power supply before starting downlod/upload and then inform the User that he should (for example) turn WiFi on to perform operation on such a big file.

You can choose from:

// small files but via 3G and on Battery
liveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.AllowCellularAndBattery;

// larger files via WiFi, on Battery
liveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.AllowBattery;

// huge files but only WiFi and External power
liveClient.BackgroundTransferPreferences = BackgroundTransferPreferences.None;

The default setting is none - so if you hadn't changed it, your App will wait for external power and WiFi - that is probably why it is working while connected via USB (external power).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top