Xamarin Forms - What is the current device/system type? - xamarin

I was working by debug my app with a Microsoft Phone 10 when I realized "UWP is a cross windows logic", so now I'm working with my computer.
However, a question comes up in my mind :
How can you know/get information about what type of system your app is running on?
I mean by this question, by example, does my app is currently running on a phone or on a computer?
Thank for your help !

In PCL or SAP
The static Device class includes several properties and methods that allow your code to deal with device differences at run time in a very simple and straightforward manner:
The Device.OS property returns a member of the TargetPlatform
enumeration: iOS, Android, WinPhone, or Other. The WinPhone member
refers to all the Windows and Windows Phone platforms.
The Device.Idiom property returns a member of the TargetIdiom
enumeration: Phone, Tablet, Desktop, or Unsupported.
You can use these two properties in if and else statements, or a switch and case block, to execute code specific to a particular platform.
Device

Related

What is the Idiom type for Xbox?

I have a UWP app created using Xamarin.Forms and I uploaded it on Microsoft Store, I enabled Microsoft to decide which platforms can I support, Xbox was automatically selected by Microsoft. I cant unfortunately test it since I dont have Xbox or any emulator available. But I am seeing that there are some downloads and Microsoft Developer Console shows the type as "Console"...
Now my question is on Xamarin.Forms doesnt have that idiom as Console, it is defined here as phone, tablet, desktop, tv, Unsupported... how to check for Xbox?
This is not built into Xamarin.Forms, so you will have to use Windows-specific API to recognize if the app is running on Xbox. You can implement a custom Dependency service that will have an interface which you will implement in UWP project. The documentation will tell you how to do it.
Then to check which type of device the app is actually running on you can check the value of:
Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily
This property contains a value depending on which type of hardware the app is currently open:
"Windows.Xbox"
"Windows.Mobile"
"Windows.Desktop"
"Windows.Team"
"Windows.IoT"
"Windows.Holographic"

Does Xamarin support to develop apps for Windows surface and how well?

I want to develop an app for Windows surface tablet and iOS mobile and iPad.
As I am a new user to Xamarin, when I created my first project,it shows 3 projects:-
hello.driod, hello.ios and hello.winPhone.
I have 3 questions based on this:-
How will I be able to write the same code and share for windows 8.1 and iOS?
and whenever I drag and drop the elements to the UI page, will the same elements be copied to both windows and iOS simultaneously or I got to add them seperately?
Currently I dont have a MAC to connect to my PC. Can I write the code and and there while testing it, connect it to a MAC or should it be connected during the whole process?
Please Help!
Using the same code depends on how your structure your app.
You can go the native route where you can share the bulk of your logic by containing it in a shared / PCL project (more on that here), but have platform specific code for your UI.
For example, if you have a cross platform app targeting iOS and Android you would still create the UI in a storyboard for iOS and AXML files for Android. Any code you want to "connect" to your UI would be specific to that platform as you would use the platform APIs. Any code that is not platform specific (i.e., not calling iOS or Android APIs) can go in your shared / PCL project.
Or you can choose Xamarin.Forms which adds a layer of abstraction by allowing you to write the UI in XAML once and have it work on all platforms. The advantage is increased code sharing as now your UI is also shared. The downside is to utilise platform specific features you'll need to implement DependencyService or custom renderers. Read more about Xamarin.Forms here.
As above, it depends. If you are going the native route, then no. If you are going with Xamarin.Forms, then you are using the same XAML code for the UI across platforms, but there is no drag and drop designer.
To build an iOS app you need to be connected to a Mac. You will also need to be connected to a Mac to use the iOS Designer.

codenameone UI distorts on Windows phone

I am trying to build a UI which should work on all mobile platforms. But currently the UI is getting distorted on Windows Phone. (Displays correctly on other devices like Android, IOS..). The text boxes are places one below other but are getting overlapped on each other, truncating the bottom part of each text box.
Need to know the correct way to design the UI, so that it should display properly on all mobile platforms.
The Windows Phone target is a dead end target as Microsoft has effectively abandoned the platform. We are now focusing on the Universal Windows Platform and have a developer guide section for it here.

Is there any way to make a First Person Shooter input in Windows 8.1?

I am working on a Windows 8.1 store game.
There is no specific need for the game to be a windows store app but I use it for development since I already had code for windows store and didn't bother to migrate the input and game loop code to a traditional desktop app.
The issue I am having now is that the Pointer(which can be a mouse/touch/pen) is bound to the screen's resolution.
I didn't find any way to work around it or to set the mouse cursor so I can't create a first person shooter like aimer or pointer.
I know it is possible to do so in a traditional win32 desktop app but I wonder if this limitation is only for Windows Store apps or will I encounter the same limitation in a traditional desktop app that runs on Windows 8.1?
In other words is this limitation a Windows 8.1 thing? Or a Windows store app thing?
Is there a way to create a FPS like mouse/aimer in a windows 8.1 store app?
You can remove the app window bounds limitations and it is possibly even easier than in a Win32 app. The only thing you need to do is this:
Window.Current.CoreWindow.PointerCursor = null;
From now on handle this event to get the delta values when the mouse moves:
MouseDevice.GetForCurrentView().MouseMoved
I use it here.

Launch/execute generic actions in Windows Phone, like Intents on Android

The Android framework allows for generic actions to be completed by any installed application that registers to handle the action. You can qualify the actions with additional data, mime types, etc.
Does Windows Phone have a similar mechanism? Is there a generic way to "launch a browser with this url", "select a file of type .xyz", "share/send this file of type .xyz", etc?
This capability does not exist to define "Intents" as it does for Android in the current v1 release of the Windows Phone SDK.
There are however a number of built in "Tasks" that behave in much the same way, including launching a Web Browser. Details here.
How to: Use Launchers for Windows Phone
How to: Use Choosers for Windows Phone

Resources