Home Screen Kit for Android 1.0.0 · manual

Home Screen Kit for Android manual

Version 1.0.0. A short overview is in the README.md file and the release history is in the CHANGELOG.md file, both in the root folder of the package. Online: https://luanrobs.com/home-screen-kit/docs/

Overview

Home Screen Kit for Android adds three ways to reach your game from outside it:

  1. Home-screen widgets. You define a widget as an asset: a size and a tree of elements (text, numbers, buttons, images, progress bars, countdowns, clocks). Your game changes what it shows with a few setter calls and Publish().
  2. Launcher shortcuts. The entries that appear when the player long-presses your app icon, and the shortcuts a player pins to the home screen.
  3. Quick Settings tiles. A tile in the notification shade that opens your game.

Every tap on any of them arrives in C# as one event, HomeScreenKit.Activated.

At build time the package generates the Android classes, layouts and manifest entries inside its own Android library. Your project's manifest is not edited. The Java source is compiled by Unity's Gradle build. There is no AndroidX, Kotlin or third-party code, and no server or account behind it. The namespace is Luanrobs.HomeScreen.

What a widget is. A widget is a set of Android RemoteViews drawn by the launcher. It shows data, not a running game. It cannot run a scene, animate, play video or sound, scroll a list or take text input. To show something visual from your game, set a snapshot of a Texture2D or RenderTexture.

Requirements

  • Unity 6000.0.84f1 or newer. Tested with 6000.0.84f1 and 6000.3.12f1 only; the results are in Tested on.
  • Android 8.0 (API 26) or newer on the device. You can install the package in a project whose minimum API level is lower. The Java library declares minSdk 23, and on a device below API 26 every component is disabled: no widget, shortcut or tile exists, HomeScreenKit.IsSupported is false and every call returns HomeScreenResult.Unsupported. This was run on API 25 and API 23 emulators and the game ran without a crash.
  • A Gradle build. The package hooks IPostGenerateGradleAndroidProject and writes into the Gradle project. Both Activity and GameActivity application entries work.
  • Scripting backends. IL2CPP (ARM64, x86_64) and Mono (ARMv7, the architecture Unity's Mono backend builds for Android) were built and run.
  • Built-in modules. com.unity.modules.androidjni, imageconversion and jsonserialize. Nothing else is a dependency.
  • The Demo sample needs uGUI (com.unity.ugui). The package itself uses neither uGUI nor TextMeshPro.
  • Android is the only platform. There is no iOS version: it needs WidgetKit, and no Mac was available to build or test it. On every other platform the API compiles and returns Unsupported.

If you embed the package in a project that does not have com.unity.test-framework, the package's test assemblies are skipped by a version define. A project without the test framework and without uGUI compiled with no errors on Unity 6000.0.84f1.

Installation

  1. Open the Package Manager: Window > Package Manager in Unity 6.0, Window > Package Management > Package Manager in Unity 6.3.
  2. Select My Assets and find Home Screen Kit for Android.
  3. Click Install.

Menus appear under Tools > luanrobs > Home Screen Kit:

Menu item What it does
Settings Creates the settings asset and registers it for the build, or selects the active one
Widget Preview Opens the approximate preview and simulator window
Validate Opens the validator window
Last Build Report Shows what the last Android build generated
Documentation Opens the online manual (on your click)

Quick start

This takes a project from nothing to a widget on a device.

  1. Settings. Choose Tools > luanrobs > Home Screen Kit > Settings. It creates a HomeScreenSettings asset and registers it as the active settings. Only definitions listed in the active settings are built. With no registered settings the package generates nothing and is inert (validator rule V01).
  2. Widget. Choose Assets > Create > luanrobs > Home Screen Kit > Widget. Set an Id (for example idle_gold; lowercase letters, digits and _, starting with a letter, up to 32 characters) and a Label (the name in the launcher's picker). Element 0 is the root container. Add a Number element with the id gold and a Text element with the id status. Add the widget to the Widgets list of the settings asset.
  3. Code. Update the widget from your game:
using System;
using Luanrobs.HomeScreen;
using UnityEngine;

public sealed class GoldWidgetDriver : MonoBehaviour
{
    [SerializeField] private HomeWidget gold;

    private void OnEnable() => HomeScreenKit.Activated += OnActivated;
    private void OnDisable() => HomeScreenKit.Activated -= OnActivated;

    public void Refresh()
    {
        gold.SetCounter("gold", new HomeCounter(1240, 0.5, 5000, DateTime.UtcNow))
            .SetText("status", "Chest is filling")
            .Publish();
    }

    private void OnActivated(HomeScreenActivation a)
    {
        if (a.Action == "collect") OpenCollect(a.Payload);
    }

    private void OpenCollect(string payload) { }
}
  1. Validate. Choose Tools > luanrobs > Home Screen Kit > Validate and fix the errors. Messages say how to fix each one.
  2. Build. Switch to Android, build and install. Long-press the home screen, open the widget picker and add your widget.

In the Editor the same code runs against a simulator, so Publish() succeeds and the Widget Preview window shows the result (see The Editor).

Widgets

The definition

A HomeWidget asset has these fields:

Field Meaning
Id Unique in the build. Becomes part of a generated class name and appears in events
Label Name in the launcher's widget picker
Description Text in the picker on Android 12+
Default Cells Size when placed, in launcher cells (columns, rows), 1 to 5 each. Default 2 x 1
Min Cells Smallest size the user may resize to. Default 1 x 1
Max Cells Largest size on Android 12+; 0 x 0 for no limit
Resize None, Horizontal, Vertical or Both
Preview Image Picture in the picker before Android 12; Android 12+ shows the layout itself. Empty uses the app icon
Update Period Minutes System refresh period: 0 for none, or at least 30
Elements The layout, as a flat list

Limits: 16 widgets, 4 tiles and 4 static shortcuts per build; 40 elements per widget; nesting depth 6; 4 dynamic images per widget.

Elements

The layout is a flat list. Element 0 is the root and must be a Stack, Row or Column with parent = -1. Every other element names its container by index in parent, and that container must come earlier in the list, so the list is also the draw order.

Type Android view Runtime setters
Stack FrameLayout, children on top of each other SetVisible, SetPayload
Row Horizontal LinearLayout SetVisible, SetPayload
Column Vertical LinearLayout SetVisible, SetPayload
Text TextView SetText, SetVisible, SetPayload
Number TextView, formatted on the device SetNumber, SetCounter, SetVisible, SetPayload
Button Button SetText, SetVisible, SetPayload
Image ImageView SetImage (when Dynamic Image is on), SetVisible, SetPayload
Progress Horizontal ProgressBar, 0 to 1 SetProgress, SetVisible, SetPayload
Chronometer Chronometer, ticked by the launcher SetCountdown or SetStopwatch, SetVisible, SetPayload
Clock TextClock, ticked by the launcher SetVisible, SetPayload
Spacer Empty FrameLayout SetVisible, SetPayload

Common element fields: width and height mode (Wrap, Fill or Fixed in dp), weight inside a Row or Column, horizontal and vertical alignment, padding, background colour, corner radius, initial visibility, action and payload for taps, text size in sp, text colour, style (Normal, Bold, Italic, Bold Italic), font (Sans Serif, Sans Serif Medium, Sans Serif Condensed, Serif, Monospace; system fonts only), and max lines (1 to 4).

A setter that does not fit the element's type, or an unknown element id, throws an ArgumentException naming the widget, element and type. Text is limited to 256 characters and action or payload to 1024.

Colours: light, dark and Material You

Each colour is None (platform default or transparent), Custom with a light and a dark value, or System, a Material You role (Surface, OnSurface, SurfaceVariant, OnSurfaceVariant, Primary, OnPrimary, PrimaryContainer, OnPrimaryContainer, Secondary, SecondaryContainer, OnSecondaryContainer, Tertiary). On Android 12+ a System colour follows the wallpaper palette. Below that it uses the light and dark fallbacks you set. Dark colours apply with the system's dark theme without the game running. Colours are set in the definition; there is no run-time colour setter in 1.0.

Publishing

Setters collect changes and return the widget, so you can chain them. Publish() sends them to the device, where they are merged into the stored state and every placed copy of the widget is redrawn:

widget.SetText("status", "Ready").SetProgress("bar", 0.4f).SetVisible("badge", true).Publish();
  • Publish() can be a UnityEvent target. PublishAsync() returns an Awaitable<HomeWidgetPublishResult>; await each one once.
  • HomeWidgets.PublishAll() publishes every widget that has pending changes. HasPendingChanges tells you whether a widget has some.
  • The result of every publish arrives in HomeWidgets.Published with the widget id, a HomeScreenResult, a message and the number of placed copies that were rendered. Zero copies is a valid success: the state is kept and shown when the widget is placed.
  • A widget that was never published shows the definition's defaults. ResetState() drops the stored state and timeline.
  • PlacedCount is the number of copies on home screens right now.
  • Every DateTime you pass is read as UTC when its kind is Unspecified and converted when it is Local.

Measured: with the game in front, a publish was visible in the QA host after a median of 82 to 172 ms (p95 189 to 283 ms), 20 publishes per device. The host polls every 250 ms, so these are upper bounds.

Counters

SetCounter makes a Number element grow while the game is closed:

new HomeCounter(value, perSecond, cap, startUtc, refreshMinutes: 15)

The displayed value is min(cap, value + perSecond x seconds since startUtc), recomputed each time the widget renders. A rate of 0, below 0 or NaN keeps the value constant: counters never shrink. A start value already over the cap is shown as it is. refreshMinutes (1 to 1440, default 15) is the least time between two re-renders while the game is closed; the widget does not re-render once the cap is reached.

Number elements print in the device's locale: 0 to 3 decimals, optional grouping, optional K/M/B/T abbreviation, a prefix and a suffix. Values are truncated toward zero and never rounded up, so an idle game does not show 1.0K at 999.6. C# (Editor preview, simulator) and Java (the device) follow the same rules.

A counter updates in steps, not continuously. To make a widget look alive, pair it with a countdown to the moment the counter is full.

Countdowns and stopwatches

A Chronometer element is ticked by the launcher itself, so it keeps counting with the game closed and without any alarm. SetCountdown(id, endUtc) counts down to a time. SetStopwatch(id, startUtc) counts up from a time. The Chronometer format is a string with %s for the time (MM:SS or H:MM:SS).

A countdown has two display styles:

Style Shows After the end
Timer (default) A ticking timer The launcher keeps counting and shows negative time such as -00:05 until the widget re-renders. Then it shows the Finished Text, or 00:00 when that is empty
EndTime A static line from the End Time Format, default Ready at %s, with the end time in the device's short time format and 12 or 24-hour setting Never negative. Shows the Finished Text

Why two styles. The launcher draws a Chronometer and nothing in RemoteViews stops it at zero. The widget can only switch to the finished text when the package re-renders it, and that re-render comes from an inexact alarm that can be late (see While the game is closed). Until it runs, a Timer countdown shows negative time. EndTime does not tick, so it has nothing to get wrong. It costs you the live ticking. Use EndTime when a negative time would look like a bug (the demo's chest uses it). Use Timer when the live ticking matters more and a few seconds of negative time after the end is acceptable. The validator warns about a Timer countdown with a Finished Text (V32).

Measured, process killed and screen on, the launcher kept showing negative time after the end for: 2.3 s, 159 s and 209 s on the Android 16 emulator, and 13.3 s, 0 s and 0 s on the Android 8.0 emulator. On the Galaxy S23 with Battery saver on it was still negative after 13 minutes.

A Clock element (TextClock) shows the current time with a 12-hour and a 24-hour pattern (java.text.SimpleDateFormat letters) and an optional time zone id.

Timeline

A timeline pushes future states to the device, which applies them at their times while the game is closed:

var timeline = new HomeWidgetTimeline();
timeline.At(midnightUtc).SetVisible("status", false);
timeline.At(eveningUtc).SetVisible("status", true).SetText("status", "Streak at risk!");
widget.SetTimeline(timeline).Publish();
  • At most 64 frames. A frame holds SetText, SetNumber, SetProgress, SetCountdown, SetStopwatch, SetVisible and SetPayload. Images and counters are not allowed in a frame and throw an ArgumentException at SetTimeline.
  • Frames at or before the time of the publish are applied at once, in order. SetTimeline(null) or an empty timeline clears the timeline.
  • Frames are applied by an inexact alarm. Frames closer together than the alarm window may be applied together.
  • Ids and types are checked when you call SetTimeline.

Snapshots and the image budget

SetImage(id, texture) takes a Texture2D (readable or not) or a RenderTexture, copies it on the GPU, scales it down to the element's Max Image Pixels on its longest side (64 to 1024, default 512, aspect kept), encodes it as PNG and stores it. The game can change or release the texture right after the call. Publish waits for the snapshot, which takes a few frames. A publish made while the game is pausing or quitting (OnApplicationPause(true), OnApplicationFocus(false), OnApplicationQuit) is completed at once, with one GPU sync, because the player loop stops when the game goes to the background and the process may be killed there. Snapshots still waiting when the game pauses or loses focus are completed the same way. This was run in the Editor (PlayMode tests), not with a real pause on a device. The element must have Dynamic Image on. SetImage(id, byte[] png) takes PNG bytes you already have (up to 1024 pixels on each side, else ImageTooLarge).

Images in Image elements that are not dynamic are converted to PNG at build time on the CPU.

The per-device budget. Android refuses a widget update whose bitmaps are too large. The limit is the platform's: 1.5 x 4 bytes x screen pixels per update. The package computes it at run time for each device. Measured values: 15,552,000 bytes on 1080 x 2400 emulators and 20,217,600 bytes on the Galaxy S23. Over the limit, the platform throws an IllegalArgumentException ("exceeds maximum bitmap memory usage"), which the package reports as ImageTooLarge.

Plan with 4 bytes per pixel: one 512 px square snapshot is 1,048,576 bytes, 4 x 768 px is 9,437,184 bytes (fit on every device run), 4 x 1024 px is 16,777,216 bytes (failed on the emulators, passed on the Galaxy S23 in an early device run). If a publish is over the device's budget the package halves the largest image until it fits and says so in the message of the publish result. Measured: 4 images of 1024 px exceeded the budget and one image was reduced to 512 x 512. If an image cannot fit at all it is left out and HomeScreenKit.Failed is raised with ImageTooLarge. The validator estimates the cost per widget with a 1080 x 2400 screen (V12).

Snapshot orientation: upright on Direct3D 11 in the Editor and on a Galaxy S23 with Vulkan. GLES3 on the Galaxy S23 was not checked.

Pinning a widget

widget.RequestPin(payload) asks the launcher to place the widget. The game must be in the foreground. The system shows its own dialog, and HomeWidgets.Pinned is raised only if the player accepts: Android reports no refusal and no cancel, so check PlacedCount when the game resumes. HomeWidgets.IsPinSupported tells you whether the current launcher offers it. Results: Ok, Unsupported, PinUnsupported, NotInBuild or NotForeground. Two requests in a row each report their own pin.

Run: pinning through the QA host on the emulators, and through One UI's dialog on the Galaxy S23.

Launcher shortcuts

A shortcut has an id, a short label (10 characters recommended, 25 at most), an optional long label (25 recommended), a square icon (at least 48 px; no icon uses the app icon), an action, a payload, a rank and a disabled message. Tapping one raises Activated with Source = Shortcut.

  • Static shortcuts are listed in the settings asset and built into the app. At most 4 are shown by most launchers. Android reads them only from the activity with the MAIN action and the LAUNCHER category; the build puts them there, even when that is a splash activity and not the Unity activity (taps still go to the Unity activity). With static shortcuts and no such activity in the exported project the build fails with V34. The package must own the app's static shortcuts: if another manifest in the build already declares android.app.shortcuts, the build fails with validator rule V31 naming the file. Unity's Gradle manifest merger reports the same clash. A static shortcut cannot be changed at run time: SetDynamic and Push throw an ArgumentException for an id that is a static shortcut id.
  • Dynamic shortcuts are set at run time: HomeShortcuts.SetDynamic(list) replaces all of them, Push(info) adds or updates one (on Android 11+ it drops the lowest-ranked one when full), Remove(ids), RemoveAll() and ReportUsed(id). Icons are encoded first, so a change reaches the launcher a few frames later. HomeShortcuts.MaxCount is the launcher's limit for static plus dynamic shortcuts.
  • Pinned shortcuts are requested with HomeShortcuts.RequestPin(info), with the same rules as widget pinning. HomeShortcuts.Pinned is raised with the id. GetShortcuts() lists static, dynamic and pinned shortcuts as the system reports them, with HomeShortcutKinds flags.

Every shortcut opens the game through an invisible forwarding activity. Without it, the platform starts a static shortcut with flags that would destroy and restart a running Unity activity. Measured on the Android 8.0, 10 and 16 emulators: a static shortcut start raised Activated with the payload and the Unity process id was unchanged.

The s: prefix in static shortcut extras. The platform's shortcut parser rejects @string references in the extras of a static shortcut and drops the whole file, and the build tools turn a bare literal such as 3 or true into a number or boolean. The generator therefore writes the id, action and payload of a static shortcut as literal values prefixed with s: under extra.S_ID, extra.S_ACTION and extra.S_PAYLOAD, and the forwarding activity strips the prefix. You do not write or see this in C#: Activated gives you the original values. It matters only if you read the generated lrhs_g_shortcuts.xml or run aapt2 dump on the APK.

Errors: LimitExceeded when static plus dynamic would exceed MaxCount; RateLimited when the system rate-limits the call (it does this mostly in the background).

Quick Settings tiles

Create a tile with Assets > Create > luanrobs > Home Screen Kit > Quick Settings Tile, set an id, label, subtitle, icon, action and payload, and add it to the settings asset (at most 4). The icon is white shapes on a transparent background, square, at least 48 px; the system tints it.

tile.SetState(HomeTileState.Active, "Quick match", "3 players waiting");
  • States: Unavailable (greyed out, a tap does nothing), Inactive and Active. A null label or subtitle keeps the current one; an empty string restores the definition's value. SetState(state) alone keeps the definition's label and subtitle.
  • SetState returns Ok, Unsupported, NotInBuild or InvalidArgument. The state is stored in the background: a storage failure arrives later in HomeScreenKit.Failed as StorageFailed.
  • The subtitle shows on Android 10+ (API 29).
  • A new state shows the next time the player opens the Quick Settings panel. Tiles are standard tiles, and Android can ask a tile to refresh only if it is an active tile.
  • A tap opens the game and raises Activated with Source = Tile. With the game in front on the Android 16 emulator it produced one activation with ColdStart false.
  • tile.RequestAdd() shows the system prompt that offers to add the tile. It needs Android 13+ (API 33; HomeTiles.IsAddSupported) and the game in the foreground. It returns Ok, Unsupported or NotInBuild. The answer arrives in HomeTiles.AddRequestCompleted as NotAdded, AlreadyAdded, Added or Failed. When the system refuses the request (for example 1004, the game is not in the foreground), AddRequestCompleted reports Failed and HomeScreenKit.Failed reports NotForeground (1004) or SystemRefused (other codes).
  • Tiles are optional for players. The package never adds a tile by itself.

Taps and activations

Every tap on a widget element, a shortcut or a tile raises HomeScreenKit.Activated with a HomeScreenActivation:

Field Meaning
Source Widget, Shortcut or Tile
SourceId Id of the widget, shortcut or tile
Action The action of the element, shortcut or tile; "open" when empty
Payload The payload from the definition or the last SetPayload
AppWidgetId Android id of the tapped widget copy; 0 for shortcuts and tiles
ColdStart True when this tap started the game process
TimeUtc When the tap was received
Sequence Increases per install and never repeats

An element with an action takes the tap; elsewhere the widget's root takes it, with the root's action or "open".

  • The tap that starts the game is delivered too. It is queued until the first subscriber is added and delivered on the next frame. HomeScreenKit.TryGetLaunchActivation gives you the activation that started the process, for code that runs before it can subscribe, such as Awake of the first scene: the package reads the launch intent before the first scene loads and waits up to 250 ms once, at start, for the Android UI thread to do it. If no subscriber is added, up to 16 activations wait (the oldest is dropped and a warning is logged once).
  • While the game runs, a tap brings the same activity forward and does not recreate it. A tap on a running game arrived with ColdStart false and no activity was created or destroyed. Measured with Activity and GameActivity.
  • HomeScreenActivationListener (Add Component > luanrobs > Home Screen Kit Activation) forwards Activated to a UnityEvent with the payload, filtered by source, id and action.
  • A throwing subscriber is logged and the others still run.
  • The package does not use a deep link: Application.deepLinkActivated is not raised and Application.absoluteURL stays empty.
  • Only taps built by the package are delivered. The Unity activity is exported (it is the app's launcher), so any app could start it with the package's intent action. Every widget, tile and shortcut intent carries a random per-install token kept in the app's no-backup folder; an intent without it is ignored and a warning is logged once. Still check payloads in your game as you would any input.
  • A tap closes other activities of your app that sit on top of the game, such as an open purchase or ad screen. This follows from the launch flags and from Unity's singleTask launch mode; it was not run with a second activity on top.
  • A relaunch from the Recents screen after the process died does not repeat the old tap. This was not run.

Force stop on Android 16

After the player uses Force stop in the system settings, Android blocks the app's broadcasts and cancels its alarms until the next launch. Taps behave differently by version:

  • Android 8.0 and Android 10: the first tap on a widget opens the game.
  • Android 16 (API 36): the first tap after Force stop does nothing visible. Android unstops the app and sends it a refresh, the widgets get fresh tap targets, and the second tap opens the game. Measured on an Android 16 emulator and on a Galaxy S23: 2 taps.

Tell players to tap again, or to open the game once. Every game start re-renders all placed widgets with fresh tap targets and re-arms the alarms.

Countdowns and clocks keep ticking after Force stop because the launcher runs them. Counters and timelines stop until the game is opened once.

While the game is closed

"Closed" means the process is not running: killed in the background, swiped away on stock Android, or after a reboot.

What Closed game
Chronometer, Clock Ticks in the launcher, no alarm needed
Counter Recomputed each time the widget renders; re-rendered by an alarm at the refresh interval
Timeline frames, Timer countdown finish Applied by an alarm
Update Period Minutes Adds the system's own periodic refresh, which only re-renders
After a reboot, an app update or a clock, time zone or locale change Re-rendered and alarms re-armed (Restore After Reboot in the settings, on by default)

Alarms are inexact. The package uses one alarm per widget with a window and no wake-up, and never asks for exact-alarm permission. A non-wakeup alarm is not delivered while the device sleeps and can be batched in Doze maintenance windows. On Android 12 and newer the system stretches any alarm window shorter than 10 minutes to 10 minutes. Do not rely on an update at an exact second, and do not use a timeline for frames seconds apart.

Measured lateness, process killed and screen on. These are few samples:

Device Result
Android 8.0 emulator, 60 s window Early run: 13.4 s, 0.007 s, 0.005 s late. Later run: 27 s late
Android 10 emulator Later run: 0.7 s late
Android 16.1 emulator, 10-minute window Early run: 1.2 s, 208 s and 158 s late. Later run: 244 s late
Galaxy S23, Android 16, Battery saver on Not delivered within 13 minutes (early run) and within 840 seconds (later run)

Plan for Android 12 and newer: an update within about 10 minutes while the screen is on, and later while the device sleeps.

Battery saver

Battery saver holds a closed game's alarms until it is turned off or the game is opened. On the Galaxy S23 the phone was in Battery saver (low_power=1), and dumpsys alarm showed battery_saver=+364d for the alarm, and for another app's alarm too. Tell players that countdown tickers still run but counters and timelines may stop updating in Battery saver.

OEM battery managers can delay or stop updates the same way. One UI's "sleeping apps" and "deep sleeping apps" restrict apps that have not been used for days. No OEM battery manager other than Battery saver on the Galaxy S23 was tested.

Cost of a closed game

A widget broadcast to a closed game starts the process and renders without starting Unity. Measured: the first render came 95 ms (Galaxy S23) to 236 ms (Android 16 emulator) after process start, and the process used about 8.5 to 9.9 MB (PSS). Unity starts only when the player taps.

Results and errors

Programming errors throw at the call: a null argument (ArgumentNullException), an unknown element id or wrong setter for the type, text or payload over the limit, a bad timeline frame (ArgumentException), and any call off the main thread (InvalidOperationException).

Platform and I/O failures never throw. A call returns a HomeScreenResult, an asynchronous failure is raised in HomeWidgets.Published or HomeScreenKit.Failed, and each code is logged once per session as [Home Screen Kit] <Code>: .... Nothing is logged on success.

Result Meaning
Ok Done or accepted
Unsupported Not an Android device, Android below 8.0, or no launcher support
NotInBuild The widget, tile or shortcut is not listed in the active settings
InvalidArgument The platform refused an argument
PinUnsupported The launcher does not accept pin requests
NotPlaced The operation needs a placed widget and none is placed
RateLimited The system rate-limited the call
LimitExceeded A fixed limit was reached
ImageTooLarge An image did not fit the bitmap budget even after downscaling
NotForeground The call needs the game in the foreground (pin request, add-tile prompt)
StorageFailed Reading or writing the package's files or preferences failed
SystemRefused The system refused the request
Busy A request of the same kind is still running
Cancelled A publish was dropped before it reached the device, by ClearAllData or ResetState; nothing was sent. Raised in HomeWidgets.Published and PublishAsync, not in HomeScreenKit.Failed
Internal Anything else; the message has the detail

HomeScreenKit.ClearAllData() deletes every stored widget state, timeline, tile state and image and removes all dynamic shortcuts. Placed widgets go back to their defaults. Publishes still waiting for a snapshot complete with Cancelled; images the game writes after the call are kept. HomeScreenKit.IsSupported, IsSimulator, AndroidApiLevel and BuiltWidgetIds describe the environment.

Validator rules

The validator runs from Tools > luanrobs > Home Screen Kit > Validate, in the inspectors, and in the build. E is an error, W a warning, I an info.

Id Severity Rule
V01 I No settings registered: nothing is generated
V02 E More than 16 widgets, 4 tiles or 4 static shortcuts
V03 E Invalid or duplicate widget, tile or shortcut id
V04 E Empty widget, tile or shortcut label
V05 W / E Tile label over 18 characters (W). Short label over 10 (W) or over 25 (E). Long label over 25 (W)
V06 E Root missing or not a container
V07 E Bad parent: not a container, not before the child, or the root has a parent
V08 E Invalid or duplicate element id
V09 E More than 40 elements or depth over 6
V10 E More than 4 dynamic images
V11 W Image with no texture that is not dynamic
V12 E / W Max Image Pixels outside 64 to 1024 (E). Estimated bitmap bytes over the budget of a 1080 x 2400 screen (W)
V13 E / W Tile without an icon (E). Icon not mostly white on transparent (W)
V14 I Shortcut without an icon: the app icon is used
V15 I No preview image: Android 11 and older show the app icon
V16 E Cells outside 1 to 5, default below min, or max below default
V17 E Update Period Minutes from 1 to 29
V18 E Action or payload over 1024 characters, or text over 256
V19 W Chronometer format without %s
V20 W Weight on an element whose parent is not a Row or Column
V21 E Fixed size of 0 or less
V22 E / W Max lines outside 1 to 4, or decimals outside 0 to 3 (E). Text size outside 8 to 64 sp (W)
V23 I System colours with a minimum API level below 31: the fallbacks are used on Android 8 to 11
V24 E Launch Activity is not a valid Java class name
V25 I Restore After Reboot is off while a widget has a Chronometer or may have a timeline
V26 W Both Activity and GameActivity are enabled as the Application Entry
V27 W Shortcut or tile icon below 48 px
V28 W Clock time zone that is not empty, UTC or in Area/City form
V29 W A custom Launch Activity not found in the exported manifest (build only)
V30 I Minimum API level below 26: components are disabled on older devices
V31 E Another manifest already declares android.app.shortcuts on the launch activity while static shortcuts are defined (build only)
V32 W Timer-style countdown with a Finished Text
V33 W Taps open an activity other than the Unity activity, so Activated would not be raised (build only)
V34 E Static shortcuts are defined but no exported manifest has a MAIN/LAUNCHER activity to carry them (build only)

The Editor: preview and simulator

Widget Preview (Tools > luanrobs > Home Screen Kit > Widget Preview) draws an approximation of the element tree from the definition, at a cell size from 1 x 1 to 5 x 4, in light or dark. The window says it is approximate: the launcher draws the real widget. In Play mode it shows the simulator's stored state and offers a Tap button on clickable elements, Advance Time for timelines and Clear Simulated Device.

The simulator. In the Editor, IsSupported is false and IsSimulator is true. Publishes succeed, RequestPin and RequestAdd succeed, shortcuts and tile states are kept, and taps come from the preview window. The simulated device persists across Play sessions through SessionState, like a real device, and is the one static that survives a domain reload. Nothing is sent to a device.

Last Build Report shows what the last Android build generated, read from Library/LuanrobsHomeScreen/last-build.json.

Domain Reload may stay disabled: statics and event subscribers are reset at SubsystemRegistration.

What the build adds to your app

When a settings asset is registered, the build step writes generated files into luanrobs-homescreen-gen/ at the root of the exported Gradle project. It deletes and rewrites that folder every build. Your project's AndroidManifest.xml and the package folder are not edited, and the entries below are merged by Gradle.

  • One receiver per widget (not exported), and one service per Quick Settings tile (exported, as the system requires).
  • An alarm receiver, a pin receiver and one invisible forwarding activity (not exported). They are always present when settings are registered, because dynamic shortcuts and pinning need them even without static shortcuts.
  • A system receiver for boot, app replacement and clock, time zone and locale changes, and the RECEIVE_BOOT_COMPLETED permission, only when Restore After Reboot is on (the default) and at least one widget is defined.
  • android.app.shortcuts meta-data on the MAIN/LAUNCHER activity, only when static shortcuts are defined.
  • Layouts, drawables, strings, colours (including values-night and Android 12 system colour overrides), provider info and the shortcut XML.

No other permission, no exact alarms and no foreground service are added. With no registered settings, nothing is added; a small fallback class keeps the library compiling. The activity taps open (UnityPlayerActivity, UnityPlayerGameActivity or a custom subclass named in Launch Activity of the settings) is the one with Unity's unityplayer.UnityActivity meta-data in the exported manifest, whether or not it is the app's launcher activity.

The package keeps its state in SharedPreferences and in the app's private files folder. Only pin and tile-add results are persisted past a process end, for 10 minutes, in a no-backup folder. Clearing the app's data removes everything, and placed widgets then show their defaults.

If R8 minification is on, the package's consumer rules keep the classes reached only by JNI. A build with minifyRelease kept them.

Samples

Open the Package Manager, select the package, open the Samples tab and import Demo. Then:

  1. Choose Tools > luanrobs > Home Screen Kit > Use Demo Settings. The demo does not register itself, so your own settings are never replaced without your action.
  2. Choose Tools > luanrobs > Home Screen Kit > Add Demo Scenes To Build. It puts the scenes 00 Menu, 01 Idle Widget, 02 Pet Snapshot, 03 Daily Streak and 04 Shortcuts And Tile at the top of the build list, 00 Menu first; importing the sample does not add them.
  3. Build for Android and install. Place the widgets from the launcher's picker.

The demo has an idle-game widget with a regenerating counter, a progress bar and a countdown (EndTime style) with a Collect tap, a pet widget with a RenderTexture snapshot, a daily-streak widget driven by a timeline, Continue and Daily reward shortcuts, a Quick match tile and a log of every tap event. In the Editor the same scenes run against the simulator. The sample needs uGUI.

Limitations

  • Android 8.0 (API 26) and newer only. No iOS.
  • A widget cannot run a scene, animate, play video or sound, scroll a list or take text input.
  • Alarm-driven updates are inexact and can be late or held by Battery saver and OEM battery managers.
  • A Timer countdown can show negative time after the end until the widget re-renders.
  • Colours are fixed in the definition; there is no run-time colour setter.
  • Labels are not localized in 1.0, and widgets have one layout for all sizes (the launcher scales it).
  • At most 16 widgets, 4 tiles and 4 static shortcuts per build, 40 elements per widget, depth 6, 4 dynamic images, 64 timeline frames, text of 256 characters and payloads of 1024.
  • A new tile state shows the next time the Quick Settings panel opens.
  • Android reports no refusal when a player cancels a pin or add-tile dialog.
  • The package must own the app's static shortcuts.
  • Launchers differ in sizes, pickers and pin dialogs. The widgets were not run in a real launcher's picker (see Not verified).
  • Google Play policy forbids using widgets, shortcuts or tiles for ads.

Tested on

Only what was run. All Unity runs were in batchmode on Windows. The Android runs used apps built from the package's demo and a QA widget set, and a QA host app that binds and draws the widgets (it acts as the home app on the emulators). It is not a launcher you can compare with the Pixel Launcher, One UI or Launcher3.

Unity tests

Unity EditMode PlayMode
6000.3.12f1 318 of 318 passed 12 of 12 passed
6000.0.84f1 318 of 318 passed 12 of 12 passed

The same counts passed in two clean projects (one per Unity version) that installed the package from its tarball and imported the Demo sample, and a check that enters Play mode three times with Domain Reload disabled passed there on both versions.

A copy embedded in a project without com.unity.test-framework (and without uGUI) compiled with no errors on 6000.0.84f1. The demo builder ran on both versions.

Android builds (all succeeded): IL2CPP with Activity and with GameActivity (ARM64 and x86_64) on 6000.3.12f1 and 6000.0.84f1 (x86_64), Mono ARMv7 with Activity on 6000.3.12f1, and minimum API 25 (6000.3.12f1) and 23 (6000.0.84f1) builds.

Android devices

Device Android Result
Emulator x86_64, API 26 8.0 Scenarios D1 to D12 with Activity and D13 with GameActivity passed
Emulator x86_64, API 29 10 D1 to D12 and D13 passed
Emulator x86_64, API 36.1 16 D1 to D12 and D13 passed on 6000.3.12f1. D2, D5, D6 and D13 passed on 6000.0.84f1
Emulator, API 25 and API 23 7.1, 6.0 Package inert: IsSupported false, tile and shortcut calls Unsupported, no crash
Samsung Galaxy S23 16 Activity: D1 to D7, D11 and D12 passed, and D10 for the shortcut listing only (the static shortcut start needs a launcher the tests control); D8 (closed-game timeline end) failed with Battery saver on. GameActivity: D13 passed. Mono ARMv7: D14 passed (armeabi-v7a, supported, Vulkan, no crash)

The Galaxy S23 also passed the early device runs for tap routing, update latency and bitmap limits.

Release check. APKs built from the clean tarball projects (IL2CPP, ARM64 and x86_64, Activity and GameActivity, one set per Unity version) passed scenarios D1 to D7 and D10 to D13 on the Android 16 emulator and on the Galaxy S23 (D10 on the phone: shortcut listing only). An intent sent by another app with the package's action and no install token was ignored on the emulator.

Figures (upper bounds, because the host polls every 250 ms)

Figure API 26 API 29 API 36.1 Galaxy S23
Publish to visible, game in front, 20 runs: median / p95 82 / 189 ms 138 / 283 ms 172 / 234 ms 119 / 194 ms
Taps after Force stop until the game opens 1 1 2 2
Timeline end with the process killed, screen on 27 s late 0.7 s late 244 s late Not delivered in 840 s (Battery saver)

Bitmap budget: 15,552,000 bytes on the 1080 x 2400 emulators and 20,217,600 bytes on the S23 (measured in an early device run). Process start by a widget broadcast and the rendering times are in While the game is closed.

Not verified

These were not run. Do not rely on them without testing on your own devices.

  • Real launchers. Widgets were drawn in the QA host, not in the Pixel Launcher, One UI or Launcher3 pickers. Cell sizes, targetCell honouring, previewLayout in a picker and the pin dialogs of those launchers were not checked, except the Galaxy S23 pin dialog of One UI.
  • Android versions not run: API 24, 27, 28 and 30 to 35 (API 31, 33 and 34 images were never installed). API 23 and 25 were run only for the inert check.
  • Doze, publishing while the game is in the background (including a snapshot publish from OnApplicationPause on a device), and more alarm samples than the table above.
  • A phone reboot (the reboot scenario ran on the emulators only), a Galaxy S23 closed-game timeline update outside Battery saver, a static shortcut start with the process id check on the Galaxy S23, and the dark theme on the Galaxy S23.
  • Material You colours and the Android 12 widget look on a real launcher.
  • requestListeningState for standard tiles.
  • Tap with another activity on top of the game, and a relaunch from Recents after process death.
  • Managed stripping level High, Export Project and Symlink Sources on Unity 6000.0, and a Gradle build of an exported project.
  • GLES3 snapshot orientation on the Galaxy S23.
  • The Widget Preview window and the inspectors in a windowed Editor.
  • iOS and other platforms: compile check only.
  • A QA-only widget that draws a 256 px image looked stretched in the QA host; the cause was not investigated.

Removing the package

  1. Delete your settings asset (and your widget, tile and settings assets). With no registered settings nothing is generated.
  2. Remove Home Screen Kit for Android in the Package Manager.
  3. Rebuild. Widgets, shortcuts and tiles of your app disappear from the launcher. Because the package never edited your manifest, nothing needs to be reverted there.

Support

Email luanrobs@gmail.com with your Unity version, Android version, device and the Last Build Report. Online: https://luanrobs.com/home-screen-kit/ , manual https://luanrobs.com/home-screen-kit/docs/ , changelog https://luanrobs.com/home-screen-kit/changelog/

I maintain and support this package myself.