Xamarin.Forms How to Create Shortcut on Android TV

Updated on 31st May 2020

I recently went down a bit of a rabbit hole trying to figure out how to create a shortcut for my Xamarin.Forms app when running it on Android TV.

Basically, most people will tick the box to enable shortcut creation when they deploy their app to the Google Play Store. And most apps deployed to Android phones & tables will automatically have an icon created.

If you've built an app for Android TV however, you will discover that after installing the app on an Android TV, it won't automatically create a shortcut on the home screen. This isn't good for my use-case because my app is isn't being deployed to the app store, instead it's being side-loaded for business use. Meaning that I need to find a way to have the application create a shortcut icon when it's installed.

Android TV without any icons

The Fix

We need to add an IntentFilter that specifies the intent of "LEANBACK_LAUNCHER".

Open up the MainActivity.cs file in your Android project and then add an intent filter to your Main Activity like I have below.

    [Activity(Label = "YourAppName",  
        Icon = "@mipmap/icon",  
        Theme = "@style/MainTheme",  
        MainLauncher = true,
        ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, 
        ScreenOrientation = ScreenOrientation.Landscape)]
    [IntentFilter(new[] { "android.intent.action.MAIN" }, 
        AutoVerify = true,
        Categories = new[] { "android.intent.category.LEANBACK_LAUNCHER" })]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

Now if you rebuild your application and test it in the emulator running an Android TV image, you'll find that a shortcut is now created.

Android TV Xamarin with shortcut

Article Categories: # xamarin.forms # xamarin # .net
Date Created: 5/31/2020
Date Last Updated: 5/31/2020

About

A tech blog by Andy P. I talk about coding, enterprise software development, tech, games design & other things that interest me.

Signup To The Newsletter

I try to post a new interesting article every saturday.