Detect headphones in windows phone 8.1 - c#

For my Windows Phone 8.1 RT app I need to detect whether headphones are plugged in.
I found this questions which answers this issue for Windows Phone 8.0 and Windows Phone 8.1 Silverlight apps:
Windows Phone - Audio Endpoint Device
It tried this code in the code-behind of my main view (actually copied from http://developer.nokia.com/community/wiki/How_to_detect_the_audio_path_(headset_connection)_on_Windows_Phone):
AudioRoutingEndpoint currentAudioRoutingEndpoint = AudioRoutingManager.GetDefault().GetAudioEndpoint();
AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged_Handler;
and the handler:
private void AudioEndpointChanged_Handler(AudioRoutingManager sender, object args)
{
var audioEndPoint = sender.GetAudioEndpoint();
switch (audioEndPoint)
{
case AudioRoutingEndpoint.Default:
{
//default audio devide
break;
}
case AudioRoutingEndpoint.Earpiece:
{
//Earpiece
break;
}
case AudioRoutingEndpoint.Speakerphone:
{
//Speakerphone
break;
}
case AudioRoutingEndpoint.Bluetooth:
{
//Bluetooth
break;
}
case AudioRoutingEndpoint.WiredHeadset:
{
//WiredHeadset
break;
}
case AudioRoutingEndpoint.WiredHeadsetSpeakerOnly:
{
//WiredHeadsetSpeakerOnly
break;
}
case AudioRoutingEndpoint.BluetoothWithNoiseAndEchoCancellation:
{
//BluetoothWithNoiseAndEchoCancellation
break;
}
default:
throw new ArgumentOutOfRangeException();
}
}
If I run this code I get this exception:
System.UnauthorizedAccessException was unhandled by user code HResult=-2147024891
Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I guess this is because the needed capabilities (ID_CAP_VOIP and ID_CAP_AUDIOROUTING) are missing.
Now my problem is that in my Windows Phone 8.1 RT app there is only a package.appxmanifest and no WMAppManifest.xml and it seems I can't define these capabilities anymore.
Please note that I really have no WMAppManifest.xml in my project as it would be in a Windows Phone 8.1 Silverlight project (there are in fact both available).
Is there a way to add these capabilities for my WP 8.1 RT app?
Or is there another way to detect headphones in Windows Phone 8.1 RT I just didn't found?
I would really appreciate any help!
EDIT: changed Windows Phone 8.1 xaml to Windows Phone 8.1 RT

So two things:
This feature is usable only during during a VOIP call, and only in the background task for the VOIP call - see the comments on this answer.
These VOIP features are only available to Windows Phone 8.1 Silverlight apps, and again, only in VOIP background tasks. So no luck for WinRT 8.1 or Universal apps. The MSDN documentation is here (A list of other features not available in Phone 8.1 WinRT here)
So.. you probably can't do what you want to do on Windows Phone (unless you're building a VOIP app).
What feature are you trying to implement with this? Maybe there is an alternative.

in WP8.1 Runtime you can create a xml file WindowsPhoneReserveAppInfo.xml with below code:
<?xml version="1.0" encoding="utf-8" ?>
<WindowsPhoneReservedAppInfo xmlns="http://schemas.microsoft.com/phone/2013/windowsphonereservedappinfo">
<SoftwareCapabilities>
<SoftwareCapability Id="ID_CAP_VOIP" />
</SoftwareCapabilities>
</WindowsPhoneReservedAppInfo>
It work fine. Good luck!

Related

How can we detect Windows 10 in Windows Phone 8.1 app?

my app (developed in Windows Phone 8.1 RT environment) uses OpenFilePicker which allows me to choose image and capture an image, it works great however when I deployed this app on a Windows 10 device, this function just allowed me to pick an image from the library. I thought about a solution, writing a small code block which can help me to detect the version of the OS like this
#if WINDOWS_PHONE_APP
//codes
#endif
But I don't know exactly what I need to do, so please help me!
Read this link:
Windows Store Apps: Get OS Version, beginners tutorials (C#-XAML)
it purpose a simple solution to check is OS has Windows 10 features with reflection:
var analyticsInfoType = Type.GetType("Windows.System.Profile.AnalyticsInfo, Windows, ContentType=WindowsRuntime");
var versionInfoType = Type.GetType("Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime");
if (analyticsInfoType == null || versionInfoType == null)
{
// That's not Windows 10
}

Windows phone 8.1 create contact task

After reverting from windows phone 8.0 to windows phone 8.1, the save contact task no longer exists. All documentation on the internet state that now
You don't have write access to the primary contact store on Windows Phone 8.1, but you have the ability to create your own contact store.
this link on msdn clearly shows how can I add contacts implicitly to my contact store.
What's strange is that WhatsApp and Telegram both allow me to create a contact and choose the account type of it (outlook, ..) and on windows phone 8.1 !
Can anyone explain this?
If you're working with wp rt, your question is a duplicate of this question.
In that case, you have to create your own contact store for the app you're working on (code copied from the linked question's answer):
using Windows.Phone.PersonalInformation;
public async void addPerson() {
var store = await ContactStore.CreateOrOpenAsync();
var contact = new StoredContact(store) {
DisplayName = "Mike Peterson"
};
var props = await contact.GetPropertiesAsync();
props.add(KnownContactProperties.Email, "mike#peterson.com");
props.add(KnownContactProperties.MobileTelephone, "+1 212 555 1234");
await contact.SaveAsync();
}
In order for your app's contacts to appear in "People", each user needs to change the filter settings of their People-App accordingly.
Yes, I did similar things myself. The reason being the upgrade to windowsphone 8.1 brought restrictions on many apis which were released on windowsphone 8.0 like access to alarms, easy phone manager tasks were all changed because they were migrated from Silverlight to a new runtime. So if you'd still like to get accept to all those classes of Windowsphone 8.0 the trick is that is you first target your app to windowsphone 8.0 OS where you get access to all the classes. And then right clicking on the package explorer do a Windowsphone 8.1 Silverlight OS update. In that sense your app gets upgraded to windowsphone 8.1 while it still retains an intermediate namespace of windowsphone 8.0 allowing you to access all classes based for the old silverlight based OS.

using SpeechRecognizerUI in my WP 8 app causing it crash unexpectedly?

I am new to windows phone app development. I am trying to build a simple speech recognition app using SpeechRecognizerUI class. But the problem is whenever i try to debug the app in my Lumia 520 device(working on 8.1 platform), it load the listener as usual and then debugger stopped automatically at the same time it load within a second, don't allow me sufficient time to speak even a single word. I am googling since 2 days but got nothing helpful. I have provided a single button on "MainPage.xml" of my app for which i have given the following code.
namespace Kundali
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private async void button_Click(object sender, RoutedEventArgs e)
{
![SpeechRecognizerUI][1] sprec = new SpeechRecognizerUI();
SpeechRecognitionUIResult result = await sprec.RecognizeWithUIAsync();
MessageBox.Show(string.Format("You said {0} ", result.RecognitionResult.Text));
}
}
When i tried to handle the exception in catch handler it shows the exception "The text associated with this error code could not be found" not even listening the single text. Some one please help me.
Actually i am working with Visual studio 2012 (Express for windows Phone 8) but my device is on 8.1. Is this the problem?? If yes then please provide the solution. How do i integrate the functionality of 8.1 in vs2012?
I can think of two possible causes:
Did you add the Speech capability and the Microphone capability in your manifest WMAppManifest.xml file?
Do you have speech support for your current language? (Try setting to en-US to test)
Did you try using TTS (Text to Speech) which is also compatible with Windows Phone 8.1?
Sample
Windows Phone 8.1 Text to Speech

Make a phone call in Windows 8.1

To make a phone call in Windows Phone 8.1 I have to do the following:
Windows.ApplicationModel.Calls.ShowPhoneCallUI(number, name);
But in Windows 8.1 app there is no class PhoneCallManager in Windows.ApplicationModel.Calls namespace. Is there any way to make a phone call in Windows 8.1 store app?
Thanks in advance!
I've just googled for you and found that link.
http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.calls.phonecallmanager.aspx
Always try to stay on the newest stand in your programming network. I also found that:
Windows Phone 8.1 [Windows Runtime apps only]
is compatible to run
public static void ShowPhoneCallUI(
string phoneNumber,
string displayName
)
I think that microsoft is still updating their classes to 8.1 but you would be able to use already some namespaces.
On Windows Phone (!) you can either use
var phoneCallTask = new PhoneCallTask
{
PhoneNumber = number,
DisplayName = "The Name goes here"
};
phoneCallTask.Show();
or
Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI(number, "The Name goes here");
Maybe you are simply missing an assembly reference?

DeviceNetworkInformation.IsCellularDataEnabled always returns false

I recently installed the Windows Phone 8.1 emulators to try some existing apps out on them and ran into this problem: DeviceNetworkInformation.IsCellularDataEnabled (in the Microsoft.Phone.Net.NetworkInformation namespace) is always returning false.
public void UpdateDataEnabled()
{
_dataEnabled = DeviceNetworkInformation.IsCellularDataEnabled
|| DeviceNetworkInformation.IsWiFiEnabled;
}
I know the connection is actually working because I'm still able to perform HTTP requests. If I run this same exact code in the 8.0.x emulators I don't have any problems.
I also tried updating the project and all libraries to Windows Phone Silverlight 8.1 apps to see if that would resolve the issue and no luck. I checked all the capabilities and ID_CAP_NETWORKING was still checked as well.
The emulator is tested and working if I write a pure Windows Phone 8.1 XAML app using Windows 8 method of obtaining network status. It's just not working for my Silverlight apps.
I was under the impression that Windows Phone Silverlight apps should continue to function on Windows Phone 8.1 devices. Am I overlooking something?
I have the same problem and i did what verdesrobert and Rishabh876 suggested. Its only emulator problem so i add condition to check out if app is running on emulator
public bool IsNetworkAvailable()
{
if (DeviceNetworkInformation.IsNetworkAvailable)
{
if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator)
{
return true;
}
else if ((DeviceNetworkInformation.IsWiFiEnabled || DeviceNetworkInformation.IsCellularDataEnabled) && NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.None)
{
return true;
}
}
return false;
}
I dont like that workaround much so if anyone has better solution let me know.
It seems that the WP8.1 emulator is giving that information only to WP8.1 apps.
I'm pretty sure that the 7.1 apps will work properly on WP8.1 Devices.

Categories