Reputation: 549
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).
I would really appreciate any help!
EDIT: changed Windows Phone 8.1 xaml to Windows Phone 8.1 RT
Upvotes: 1
Views: 952
Reputation: 137
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!
Upvotes: 1
Reputation: 1137
So two things:
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.
Upvotes: 2