How to retrieve all contacts in Windows Store app using c# - c#

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.

Related

Azure Speech To Text in Blazor app (C# SDK)

I'm trying to use the Speech C# SDK with Blazor, but even in the simplest of examples I always get NoMatch.
var result = await recognizer.RecognizeOnceAsync();
switch (result.Reason) // <-- Here I get ResultReason.NoMatch
any help would be greatly appreciated.
Geo
The method for RecognizeOnceAsync uses the default system microphone and mine was bad, when I set my default microphone to the correct one in Windows 10, the SDK started working as intended.

Windows Phone Contacts fetch/update from device

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

Where is Microsoft.Phone.UserData in Windows Phone 8.1?

I am using Windows 8.1 and Visual Studio 2013. As far as I know, everything is update to date. So what I wanted is to fetch contact list, but I am not able to the that even after googling.
According to MSDN, all I have to do is put using Microsoft.Phone.UserData and after that I can happily get contacts. The problem is, I can't, because there is an error which says that Microsoft.Phone.* doesn't exist.
Am I missing something or what. According to site above, it applies to Windows Phone 8 and Windows Phone Silverlight 8.1 | Windows Phone OS 7.1.
P.S. It's about blank app (Windows Phone) project
You are looking at the tutorial for Windows Phone 8 as against the fact that most probably you are using WinRT for Windows phone 8.1
You need to use the ContactStore class by using the ContactManager class.
Here is a code snippet from MSDN
public async void FindContacts(string searchText)
{
ContactStore contactStore = await ContactManager.RequestStoreAsync();
IReadOnlyList<Contact> contacts = null;
if(String.IsNullOrEmpty(searchText))
{
// Find all contacts
contacts = await contactStore.FindContactsAsync();
}
else
{
// Find contacts based on a search string
contacts = await contactStore.FindContactsAsync(searchText);
}
MyContactListBox.ItemsSource = contacts;
}
In case you want to target older versions of windows phone you might want to read this
In case there is a confusion in regards to what version of SDK do I use for targeting a specific version of windows phone , here is the help.
I have had the same issue, think it might be because if I look for the Microsoft.Phone class, I find it in a 8.0 directory. In my case
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0\
I then just referenced it by browsing for the file. I'm not sure what you're intending to use it for, and if the classes will be compatible with 8.1. But I hope this helps.

Windows 8,launch outlook from metro application

I am trying to open out look from metro application (vs2012, windows store app).I used the following code:
var mailto = new Uri("mailto:?rbethamcharla#hotmail.com");
await Windows.System.Launcher.LaunchUriAsync(mailto);
But I am always getting access denied error.Could some one please let know how to enable this acess of outlook from windows 8 store app programmatically.
Thanks & Regards
Ravi Kumar B
First of all Need to check the url the code should be
var mailto = new Uri("mailto:rbethamcharla#hotmail.com");
await Windows.System.Launcher.LaunchUriAsync(mailto);
then it receives the email address. Secondly you can go through the link from msdn
access outlook MSDN
Some steps might be helpful. Try making outlook your by default mail client.

Get Unique Device ID (UDID) under Windows Phone 8

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

Categories

Resources