对于我的Windows Phone 8.1 RT应用程序,我需要检测是否插入了耳机 .
我发现这个问题可以解决Windows Phone 8.0和Windows Phone 8.1 Silverlight应用程序的这个问题:Windows Phone - Audio Endpoint Device
它在我的主视图的代码隐藏中尝试了这段代码(实际上是从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;
和处理程序:
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();
}
}
如果我运行此代码,我得到此异常:System.UnauthorizedAccessException未被用户代码处理HResult = -2147024891 Message = Access被拒绝 . (HRESULT异常:0x80070005(E_ACCESSDENIED))
我想这是因为缺少所需的功能(ID_CAP_VOIP和ID_CAP_AUDIOROUTING) . 现在我的问题是,在我的Windows Phone 8.1 RT应用程序中只有 package.appxmanifest
而没有 WMAppManifest.xml
,似乎我再也无法定义这些功能了 .
请注意,我的项目中没有 WMAppManifest.xml
,因为它将出现在Windows Phone 8.1 Silverlight项目中(事实上两者都可用) .
-
有没有办法为我的WP 8.1 RT应用程序添加这些功能?
-
或者是否有其他方法来检测Windows Phone 8.1 RT中的耳机我还没找到?
我真的很感激任何帮助!
编辑:将Windows Phone 8.1 xaml更改为Windows Phone 8.1 RT
2 回答
所以有两件事:
此功能在VOIP呼叫期间可用 only ,在VOIP呼叫的后台任务中可用 only - 请参阅this answer上的注释 .
这些VOIP功能可用于Windows Phone 8.1 Silverlight应用程序 only ,并且仅适用于VOIP后台任务 . 所以WinRT 8.1或通用应用程序没有运气 . The MSDN documentation is here(其他features not available in Phone 8.1 WinRT here的清单)
所以..你可能无法在Windows Phone上做你想做的事情(除非你正在构建一个VOIP应用程序) .
你试图用这个实现什么功能?也许有另一种选择 .
在WP8.1 Runtime中,您可以使用以下代码创建一个xml文件WindowsPhoneReserveAppInfo.xml:
它工作正常 . 祝好运!