Where is Microsoft.Phone.UserData in Windows Phone 8.1? - c#

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.

Related

WPD C# Windows Phone

I am new to Windows Phone developing and I am trying to copy a file from PC to Windows Phone Documents folder. I read and tried what is written in this article Copy files with WPD to Windows Phone C#. The original article is https://dzone.com/articles/creating-apis-for-mobile-iot-apps. Unfortunately I got an error of ArgumentException in the line:
targetStream.Write(buffer, bytesRead, pcbWritten);
I think it's related to the parameter ParentObjectID, when I call the method:
device.TransferContentToDevice(#"H:\temp\QuestPhone\Pesquisas.db",#"G:\Documents");
I tried to replace "G:\Documents" by "Windows Phone:\Documents", and "Phone:\Documents" and "Windows Phone:\Phone\Documents" but without success.
So, how can I specify the "logical drive" where my Windows Phone device is connected to?
After some time I got a solution. The correct ParentObjectID is #"o1". "o1" is the ID of documents folder on the device.

Using the MediaCapture API, StartRecordToStorageFileAsync fails to return and does not raise an error

I'm trying to use this MediaCapture API sample:
https://code.msdn.microsoft.com/windowsapps/Media-Capture-Sample-adf87622
but when I press Start Record to record to a file, this line never returns:
await m_mediaCaptureMgr.StartRecordToStorageFileAsync(recordProfile, m_recordStorageFile);
And no error is thrown. This computer is a Cyberpower PC. The sample DOES work on my other windows 10 computer (a mac mini) though. I thought maybe it was a codec issue but can't find any information on installing codecs so maybe that is not it--not sure. Thank you for any help or information.
Additional Info: Creating a profile like this works:
MediaEncodingProfile recordProfile = null;
recordProfile = MediaEncodingProfile.CreateWmv(Windows.Media.MediaProperties.VideoEncodingQuality.Auto);
But calling CreateMp4 instead of CreateWmv does not work.
My suspicion is that there's something wrong with your particular installation's encoders. If you can upgrade to Windows 10, with Visual Studio 2015 you can develop universal apps. The same code should work without an issue.

How to retrieve all contacts in Windows Store app using 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.

Exception only in one PC, in others work fine

I have an exception only in one PC, in others all work fine, anyone know wher it is comming from?
dditional information: Requested Windows Runtime type
'Windows.Media.Capture.MediaCapture' is not registered.
This exception is showing only in modern style apps (windows strore app) in windows 8.1. In WPF or Windows Form apps camera works fine. Code is fine, because in other pc work great:) i install system one more time, but the exception still showing up.
Looking at Microsoft's Windows Universal Samples (https://github.com/Microsoft/Windows-universal-samples/blob/e13cf5dca497ad661706d150a154830666913be4/Samples/SpeechRecognitionAndSynthesis/cs/AudioCapturePermissions.cs#L35) shows following piece of code
try
{
// Request access to the microphone only, to limit the number of capabilities we need
// to request in the package manifest.
MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
settings.MediaCategory = MediaCategory.Speech;
MediaCapture capture = new MediaCapture();
await capture.InitializeAsync(settings);
}
catch (TypeLoadException)
{
// On SKUs without media player (eg, the N SKUs), we may not have access to the Windows.Media.Capture
// namespace unless the media player pack is installed. Handle this gracefully.
var messageDialog = new Windows.UI.Popups.MessageDialog("Media player components are unavailable.");
await messageDialog.ShowAsync();
return false;
}
So you have to install "Media player components".
I just had this issue with Windows 10. I had installed the N edition, but it looks like since it is missing Media Player, the classes related to MediaCapture are also missing.
As Hans Passant mentioned, the MediaCapture class was not registered in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId.
I reinstalled Window 10 (not the N edition) and now the class is registered.

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