LiveConnectClient.BackgroundUploadAsync, is not working when phone not connected to usb

那年仲夏 提交于 2019-12-01 20:44:23

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/22434638/liveconnectclient-backgrounduploadasync-is-not-working-when-phone-not-connected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!