Detect if share UI is supported in current device (UWP)

回眸只為那壹抹淺笑 提交于 2019-12-12 09:41:43

问题


I have created a UWP app for windows 10 devices using c#/xaml. In the app, i have a share functionality that calls DataTransferManager.ShowShareUI()

This works as expected on desktop, tablet and mobile devices. But on my xbox, the above method does not launch the share UI. Nor does it throw any exceptions. After searching online a bit, I found this article that says share contract is not supported on xbox. And no share UI is displayed. But this gives a bad user experience.

So I have 2 options now

  1. Hide the share button, if the device is an xbox
  2. Or when user clicks on share, show a popup that the feature is not supported

After hours of searching, I have still not found a reliable way to detect if my device is xbox. Microsoft discourages trying to identify the device type. Instead we should check if the API is supported using either ApiInformation.IsTypePresent or ApiInformation.IsApiContractPresent. For more info check here

But in my case, the API is present. So IsTypePresent returns true. I am not sure what parameter i should pass for IsApiContractPresent in my scenario.

In short, I need a reliable way either identify if my device is xbox or identify if share UI is supported in my device. Does anyone know how to do this?


回答1:


Windows 10 RS1 introduced IsSupported method for DataTransferManager Class: Link

I believe your Xbox device has been upgraded to RS1 or later, so you can use this method to detect if the device supports sharing.

if (DataTransferManager.IsSupported())
{
      //Do sharing
}
else
{
      //Other thing
}


来源:https://stackoverflow.com/questions/42386405/detect-if-share-ui-is-supported-in-current-device-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!