简体   繁体   中英

Xamarin forms - How to detect whether the device is touch device or not?

I am developing an app using xamarin forms cross-platform PCL project. I need to know if I can detect whether the device is touch device or not? Is it possible to detect this?

XF does not know if the device is touch or not, but you can detect the kind of device you're running on using Device.Idiom . If you get TargetIdiom.Desktop you know that, in addition of a possible touch screen, the user probably also has a keyboard and a mouse.

I suppose you are asking this to make a TV app . Well unfortunatly at this moment Xamarin.Forms cannot find that, however you can do this in the main Activity like follows

 var uiModeManager = (UiModeManager) GetSystemService(UiModeService);
if (uiModeManager.CurrentModeType == UiMode.TypeTelevision)
{
     _isTv = true;

}
else
{
_isTv = false;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM