问题
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
- Hide the share button, if the device is an xbox
- 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