Aucun résultat trouvé
December 23, 2014David Isbitski
Xamarin is a cross platform development environment that leverages the power of the C# programming language and takes full advantage of native hardware acceleration. Xamarin generates fully native code for each mobile platform instead of translating at runtime. Because Xamarin apps are built with standard, native user interface controls apps not only look the way the end user expects, they behave that way too. Xamarin also includes a suite of tools that allow you to test, build, and analyze your apps across all of the major mobile platforms. Utilizing Xamarin you can now publish your own apps and games to all Amazon Fire devices. This includes Amazon Fire tablets, Amazon Fire phone, Amazon Fire TV and the recently announced Amazon Fire TV Stick.
Please join me in welcoming special guest Mike Bluestein, who as a Developer Evangelist for Xamarin, helps developers be successful with the Xamarin platform. Mike is going to walk us through the steps to get your own apps and games running on Amazon Fire TV and Fire TV Stick with Xamarin Studio.
It’s incredibly straight forward to get started with Amazon Fire TV and Fire TV Stick when using Xamarin due to its native Android support and the freely available Fire TV component.
The version of Amazon FireOS that runs on Fire TV is based on Android Jelly Bean (API Level 17), so you can take your existing Android skills and code there by just targeting API 17. In fact, without even using the Amazon Fire TV SDK, you can run most API 17 apps without much modification. This of course depends on what you use.
The Amazon Fire TV SDK Add-on is available in the Android SDK Manager via an Add-on site, as described in the Amazon documentation. Once added, it appears under API 17:
To develop with Xamarin, the Xamarin component store includes an Amazon Fire TV component, which includes support for Amazon notification and game controller APIs respectively:
However, as mentioned, API 17 will work even without using the component. Try it yourself.
adb connect [Fire TV IP Address]
The app will deploy to the Fire TV device and you’ll be able to debug within Xamarin Studio just like any other Android application.
The Fire TV remote maps to normal Android keystroke handling. Therefore tapping the center button results in a button click in the Hello World app:
When developing for Fire TV devices, you’ll want to design especially for it. For example, here’s a simple photo viewer of the Conceptdev Monkeys. It has adequate thumbnail size and padding around the screen edges so that the user can see it fine from a few meters away.
The user can easily navigate between monkeys using the remote. When selected a large view of the monkey is displayed.
What’s really great, from a programming perspective, is this is just Android. Therefore all your skills move forward.
Apps are great, but Fire TV devices really shine in its ability to bring Android games to the TV.
I previously blogged about a simple space game I made for the Fire TV Stick, using CocosSharp, where I used the remote to control the spaceship. Let’s take a look at how to extend the game to use an Amazon Fire TV controller with the GameController API.
To use the GameController API (available in the Xamarin component) you have to:
CocosSharp games build upon MonoGame, which on Android uses the AndroidGameActivity. To use the game controller API, you must call GameController.Init after setting the ContentView:
In this case, we’ll be using the right joystick of the game controller to move the ship around the screen in any direction. Therefore, we need to forward generic motion events to the controller:
With this in place we can get input from the controller in the game layer and move the ship accordingly:
Then when we run the game, the ship moves via the right joystick:
The Amazon Fire TV family of devices and the associated SDK are fun to develop for. You can use your existing skills and resources and open the doors to a world of potential new customers!
One of the things to remember is that you’ll want to design your applications with the TV experience in mind. Applications designed for a phone won’t have a great experience on a large TV where people sit several meters away and interact via remotes and controllers, as opposed to touch.
For additional tips on optimizing Android apps for the TV experience be sure to check out this free video and this blog post. For more information about getting started with Xamarin Studio and Amazon Fire devices, check out the following additional resources:
Xamarin Getting Started with Android
Amazon Mobile Apps and Services Developer Portal