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.
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).
Related
I'm making a winform application that monitors things happening on the computer like processes, wifi, screenshots,... and I'm working on Bluetooth connection.
I need to get the notification when a Bluetooth device connects or disconnects to the computer (or laptop), for example mobile phones. In addition, I need something to identify the device like ID or just the name of it if possible.
One thing to notice, I'm using C# and it's a winform app, it would be nice if the solution uses Windows native library (like winapi, pInvoke). Third party library is fine but it would be my last choice.
Update: I've followed Rita Han's answer and got some results.
Below is my code inside the override WndProc method. It works totally fine with USB but not with Bluetooth devices.
While the app is running, I turn on Bluetooth on both my laptop and mobile phone but they have not paired yet → the function gets called and it says Bluetooth came, then I connect the two devices → now they are connected but no notification except the one above.
After that, while they are connected, I try to remove the mobile phone device, they are disconnected and I connect them back again and one more time I get no notification about a new Bluetooth connection has been scanned or connected.
So in short, I get notified when Bluetooth radio scans for a new device but not when connecting in the first time. After that, disconnecting and reconnecting do not give me any notifications also.
Am I missing some events?
case USB.DBT_DEVICEARRIVAL:
devType = Marshal.ReadInt32(m.LParam, 4);
if (devType == USB.DBT_DEVTYP_VOLUME)
{
USB.DEV_BROADCAST_VOLUME vol;
vol = (USB.DEV_BROADCAST_VOLUME)
Marshal.PtrToStructure(m.LParam, typeof(USB.DEV_BROADCAST_VOLUME));
// Get the drive letter
c = USB.DriveMaskToLetter(vol.dbcv_unitmask);
listBox1.Items.Add("New USB has come with name " + c);
}
else if (devType == BluetoothDeviceNotification.DbtDevtypDeviceinterface)
{
BluetoothDeviceNotification.DevBroadcastDeviceinterface vol;
vol = (BluetoothDeviceNotification.DevBroadcastDeviceinterface)Marshal.PtrToStructure(m.LParam, typeof(BluetoothDeviceNotification.DevBroadcastDeviceinterface));
listBox1.Items.Add("Bluetooth came GUID " + vol.ClassGuid + "\t Name: " + vol.Name);
break;
}
break;
For using Windows native API you can use RegisterDeviceNotification function.
Refer to "Registering for Device Notification" sample for getting started.
Bluetooth interface GUID:
GUID BluetoothGUID = {0x0850302A, 0xB344, 0x4fda, 0x9BE9, 0x90, 0x57, 0x6B, 0x8D, 0x46, 0xF0 };
Bluetooth and WM_DEVICECHANGE Messages.
I am trying to use a HID (DualShock 4) connected to my R-PI 3 running Windows 10 IoT in a C# universal app. I was using the Device Enumeration sample as a guideline and managed to display the IDs of all connected devices. I could see that the connected DualShock was correctly enumerated because it logged the \\?\HID#VID_054C&PID_05C4....
So naturally the next thing I wanted to do was opening the device for communication. Since it is an HID I was using the HidDevice class with var device = await HidDevice.FromIdAsync(args.Id, FileAccessMode.ReadWrite);. Sadly the returned device is always null, nothing on the screen is prompted or so.
Next I assumed there at least has to be some kind of USB interface accessible so I went for var device = await UsbDevice.FromIdAsync(args.Id);
But now I am getting A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F) or sometimes also The process cannot access the file because it is being used by another process.
How can I talk to my device? :(
For example, I have two heart rate monitors paired with my tablet PC.
I'm using such code to get list of HRM devices:
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync
(
GattDeviceService.GetDeviceSelectorFromUuid(GattServiceUuids.HeartRate)
);
Then I show a listbox in GUI with device names got from devices[i].Name.
For example, I select device with index 0. Then I can get access to it HR serivice and HRM characteristic:
var service = await GattDeviceService.FromIdAsync(devices[0].Id);
var characteristic = await service.GetCharacteristics(attCharacteristicUuids.HeartRateMeasurement);
Along with heart rate I need a battery status. How can I get access to battery service of the same (already selected) device?
Some information before we start:
You do have to pair your Bluetooth devices with your computer, before you could scan them!
Listing your paired devices:
ListBox1.Items.Clear();
var devices = await DeviceInformation.FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
foreach (var device in devices)
{
ListBox1.Items.Add(device);
}
If you want to know the battery life of the Bluetooth device:
How to get the battery level after connect to the BLE device?
To access multiple services at once, you need to "reconnect" to the device:
Device A can connect only one at a time to service S on Device B. Device A can connect to service S on Device B, C, D and E, etc at the same time.
#alanjmcf
Source: Establishing multiple bluetooth SPPs at the same time
But do not get confused with the method GetAllIncludedServices();, because it does really return "included services". As one answer stated at an other question:
You probably don't want to get the "included services". Included services is a special concept in BLE which I doubt you are using that is used to link one service from another.
#Emil
I made a UWP application. I use the roamingdata.I save the setting by this:
public static void WriteCode(string pwd)
{
ApplicationDataContainer RoamingSettings = ApplicationData.Current.RoamingSettings;
RoamingSettings.Values["Code"] = EncryptHelper.PwdEncrypt(pwd);
}
I read the setting by this:
public static string GetCode()
{
ApplicationDataContainer RoamingSettings = ApplicationData.Current.RoamingSettings;
string str = (String)RoamingSettings.Values["Code"];
if (!String.IsNullOrEmpty(str))
return str;
else
return EncryptHelper.PwdEncrypt("123");
}
I complete the application and upload to windows store and passed check. Then I download this app on my phone.
I change the ApplicationData.Current.RoamingSettings on phone. I write something to the ApplicationData.Current.RoamingFolder on my phone.
Next I closed the app on my phone and download the app on my PC. But when I opened the app on my PC, I found that the ApplicationData.Current.RoamingSettings and the ApplicationData.Current.RoamingFolder didn't change anything.
I checked the C:\Users\XXX\AppData\Local\Packages\XXX\RoamingState on my PC,there was nothing. I checked C:\Users\XXX\AppData\Local\Packages\XX\Settings on my PC,there was roaming.lock and settings.dat. But I can't read the lastest settings and roaming data that I haved added on my phone anymore.
I have waited for 2 hours, there was no change on my PC.
there is something that I should state first:
1 All the deploy work was done by windows store.
2 I check my PC application setting after closed the app on phone. I even shut down my mobile phone to observe the change to my PC.
what's wrong with my code? or what's wrong with the roamingdata mechanism? I need an answer, thank you!
The code you've posted is right. However, there are some possible reasons for the failure of roaming data sync:
Any user can benefit from roaming app data if they use a Microsoft account to log on to their device. However, users and group policy administrators can switch off roaming app data on a device at any time. If a user chooses not to use a Microsoft account or disables roaming data capabilities, she will still be able to use your app, but app data be local to each device.
Keep in mind that roaming data is associated with a user's Microsoft account. Roaming data will only sync if a user logs into her devices using the same Microsoft account and installs the app on several devices.
Don't use roaming for data that relies on instant syncing. Windows doesn't guarantee an instant sync; roaming could be significantly delayed if a user is offline or on a high latency network.
Roaming of settings is not instant. The system weighs several factors when determining when to send the data. We can detect whether new roaming data has arrived on the local device by listening for the ApplicationData.DataChanged event. This event occurs when app data has just finished syncing from the cloud. Any time a device receives new roaming data, the DataChanged event will fire, passing in the updated ApplicationData object. This lets us make any adjustments to our app when data has changed.
For important, time critical settings, use the HighPriority setting associated with RoamingSettings like following:
// High Priority setting, for example, last page position in book reader app
roamingSettings.values["HighPriority"] = "65";
This is a special key in the roaming settings we can use for data we need to sync immediately. Adding HighPriority to any setting will have it synced as quickly as possible.
Don't roam large sets of app data. There's a limit to the amount of app data an app may roam; use RoamingStorageQuota property to get this maximum. If an app hits this limit, no data can roam until the size of the app data store no longer exceeds the limit.
The name of each setting can be 255 characters in length at most. Each setting can be up to 8K bytes in size and each composite setting can be up to 64K bytes in size. The sync engine may limit the total size of settings and files that can roam. It’s important to keep track of the amount of data you’re attempting to roam. If the total amount of data you’re attempting to sync exceeds the limit, then nothing will sync between the devices.
App data only roams between installed apps with the same version number. For example, devices on version 2 will transition data between each other and devices on version 3 will do the same, but no roaming will occur between a device running version 2 and a device running version 3. If you install a new app that utilized various version numbers on other devices, the newly installed app will sync the app data associated with the highest version number.
If you are using versioning in your roaming date, please make sure you are dealing with the right version.
These are some possible reasons that can cause roaming data doesn't sync between devices. For more info, please check Roaming data in Store and retrieve settings and other app data.
I have created a windows store application that prints out network information using the using Windows.Networking.Connectivity; name space.
Although the application is running and working correctly, the MegabytesUsed method is return "Not Defined". why is this.
If you run the app in Local Machine and you are connected with ethernet you dont use DataPlan.
If you want to debug open with Simulator and enable "Use simulated network prperties" and then change Data Limit Status Flag and you will see results.
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
DataPlanStatus dps = profile .GetDataPlanStatus() ;
textBlock.Text = dps.DataPlanUsage.MegabytesUsed.ToString();