I am developing Windows Phone app (Windows Phone 8.1), and I need to have user's contacts updated in my app.
Currently I am fetching all contacts from the device on each application startup or from a background task once in a while:
var contactStore = await ContactManager.RequestStoreAsync();
var collectionOfContact = await contactStore.FindContactsAsync();
This operation costs me a lot, cause I am doing intersections with the new fetched collection and my previous data - I need to check for new and deleted users in order to perform an update on my contacts.
Is there any way to get only new contacts from the device or the deleted ones? Is there any other approach to accomplish this functionality ?
Thanks in advance
Related
I am developing a UWP application.
In which I am trying to get store product details, by the code below
StoreContext storeContext = StoreContext.GetDefault();
StoreProductResult queryResult = await storeContext.GetStoreProductForCurrentAppAsync();
Here queryResult.Product is always null.
I have associated my app Right click project > Store > Associate App with store > select app.
Kindly help me to get store product details , in debug mode.
That API, if I’m not mistaken, is only for retrieving In-app products for the current app.
I also tried once that API and it worked that way.
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'm making simply windows 10 apllication - sales manager. Only 3 tables. I have local sqlite database. I'm looking for easy way to backup this database or synchronize. Because databae is small I think about full synchro always, so for example: I'm clicking 'Send database' and full data from device is send to server. When I click 'download' all database will be downloaded. I will be grateful for advice simply way to save database
IMHO, you can take advantage of OneDrive's App Folder to backup your SQLite database.
The App Folder is a dedicated, special folder for your app. The App Folder is typically named after your app, and is found in the Apps folder in the user's OneDrive. If you request the onedrive.appfolder permission scope and the user authorizes it, your app gets read and write access to this folder.
And for C#, you can use OneDrive SDK for CSharp in your application. For example, you can send your database file like following:
private async Task<Item> UploadDBFile()
{
StorageFile DBFile = await ApplicationData.Current.LocalFolder.GetFileAsync("db.sqlite");
var oneDriveClient = await OneDriveClientExtensions.GetAuthenticatedUniversalClient(new[] { "onedrive.appfolder" });
using (var contentStream = await DBFile.OpenStreamForReadAsync())
{
return await oneDriveClient.Drive.Special.AppRoot.ItemWithPath("backup.sqlite").Content.Request().PutAsync<Item>(contentStream);
}
}
And download the db like:
private async Task DownloadDBFile()
{
var oneDriveClient = await OneDriveClientExtensions.GetAuthenticatedUniversalClient(new[] { "onedrive.appfolder" });
using (var contentStream = await oneDriveClient.Drive.Special.AppRoot.ItemWithPath("backup.sqlite").Content.Request().GetAsync())
{
StorageFile downloadedFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("DownloadedDB.sqlite",
CreationCollisionOption.ReplaceExisting);
using (var writerStream = await downloadedFile.OpenStreamForWriteAsync())
{
contentStream.CopyTo(writerStream);
}
};
}
Please note that to use OneDrive API in your application, you need to first register your application for OneDrive by following these steps.
To sync local database, you can also try with Offline Data Sync in Azure Mobile Apps. This is more powerful than backup your database.
When your app is in offline mode, users can still create and modify data, which will be saved to a local store. When the app is back online, it can synchronize local changes with your Azure Mobile App backend. The feature also includes support for detecting conflicts when the same record is changed on both the client and the backend. Conflicts can then be handled either on the server or the client.
Offline sync has a number of benefits:
Improve app responsiveness by caching server data locally on the device
Create robust apps that remain useful when there are network issues
Allow end-users to create and modify data even when there is no network access, supporting scenarios with little or no connectivity
Sync data across multiple devices and detect conflicts when the same record is modified by two devices
Limit network use on high-latency or metered networks
For more info, please refer to Offline Data Sync in Azure Mobile Apps, Enable offline sync for your Windows app, and the Todo offline sample in GitHub.
I'm writing Universal app (WinStore 8.1 + WinPhone 8.1). For my requirements I need to retrieve all device contacts. It's OK on WinPhone - here is code how I do that:
var contactStore = await ContactManager.RequestStoreAsync();
var contacts = await contactStore.FindContactsAsync();
But how to do that in WinStore app?
It is not possible by design I am afraid.
Tt's not possible to get the information from the people app. It works within calendar, mail or messenger because they're all technically contained within the same app and are able to use each other's data and violate normal rules.
You can always use the ContactPicker.
This might help.
Is there any unique device ID (UDID) or any similar ID I can read out on Windows Phone 8 (WP8) that doesn't change with hardware changes, app-reinstallation etc.?
In older Windows Phone versions there were such IDs:
WP7: Device Status for Windows Phone
WP7.1: DeviceStatus Class
But they doesn't work anymore with SDK 8.0.
Why I ask:
The idea is that a user gets some free credits with the first start of the the app and I want to avoid that the user just re-installs the app for getting new free credits. A registration with email or phone number could solve this, but if I can, I don't want do bother users at the first start with a registration.
---///---SOLUTION----------
I can confirm that DeviceExtendedProperties.GetValue("DeviceUniqueId") still works in WP 8.0. Got a little bit confused when I read the following text:
In Windows Phone OS 7.0, this class was used to query device-specific
properties. In Windows Phone OS 7.1, most of the properties in
DeviceExtendedProperties were deprecated, and the new DeviceStatus
class should be used instead. However, where appropriate, you can
still use any of the below properties that are not deprecated.
MSDN:DeviceExtendedProperties Class
I can run the following code, delete the app and re-install it and get the same ID:
byte[] myDeviceID = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
string DeviceIDAsString = Convert.ToBase64String(myDeviceID);
MessageBox.Show(DeviceIDAsString);
I haven't yet started to develop for Windows Phone 8, still on 7, but you still should be able to use the original DeviceExtendedProperties class to pull back the Device Unique ID.
DeviceExtendedProperties.GetValue("DeviceUniqueId")
I've had this issue with returning the null value. Then remembered that it needs to be switched on.
In WMAppManifest.xml -> Capabilities tab -> switch on ID_CAP_IDENTITY_DEVICE
There's a twist to this DeviceUniqueId - it is unique only for one publisher. So it is not really device-wide unique identifier but unique device id for one publisher. We have noticed when we worked on some customer project where we tried to identify the same phone from different accounts (customer publishes under two different accounts).
You can get your own wp8 device Id by DeviceExtendedProperties.GetValue("DeviceUniqueId")
Here is the simple way to get deviceId as a string
byte[] id = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
string deviceID = Convert.ToBase64String(id);
By not providing DeviceUniqueId in Windows Phone 8 and Windows 8, Microsoft tried to avoid User Tracking but with increased pressure from Dev community, they are bringing it back again.
In Windows 8.1, Microsoft has introduced a new AdvertisingId API and may also bring similar Id to identify a unique user across apps in subsequent Windows Phone 8.1/9 versions.
I used this:
private static String getDeviceId()
{
byte[] id = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
return BitConverter.ToString(id).Replace("-", string.Empty);
}
But the key is to Check the ID_CAP_IDENTITY_DEVICE in WMAppManifest, or else it throws error.
I found this a new HostInformation.PublisherHostId property
More info at
http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.system.analytics.hostinformation.publisherhostid.aspx..
string myDeviceID = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId");
string DeviceIDAsString = Convert.ToBase64String(myDeviceID);
I have used this for windows phone unique device Id.
The answers above work for Windows Phone 7 and 8 Silverlight. However, they will not work for Windows Phone RT (Universal) or Store Apps since the SDK does not have this dll library (Microsoft.Phone).
This is how you get the device ID and Name (and possibly other info) on Windows Phone 8.1 RT (Universal/Store Apps).
private string GetHardwareId()
{
var token = HardwareIdentification.GetPackageSpecificToken(null);
var hardwareId = token.Id;
var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] bytes = new byte[hardwareId.Length];
dataReader.ReadBytes(bytes);
return BitConverter.ToString(bytes);
}
More details about reading the device info on Windows RT can be found here