How to create a widget for Xiaomi: from idea to publication

Creating your own widget for Xiaomi devices is a great way to personalize the interface MIUI Widgets can bring useful real-time information to the home screen, from weather and currency rates to smart home management or quick access to app features. Unlike standard icons, widgets are interactive and can update data without opening a program.

In this article, we will discuss the entire process - from preparing the development environment to publishing a ready-made widget in the Mi App Store. API, customize MIUI, Test the solution on different Xiaomi models (from Redmi Note to Mi 14) and avoid typical errors.

Important: The process of creating a widget requires basic knowledge Kotlin/Java If you've never written an Android app, start by learning the basics β€” without it, it's going to be extremely difficult to develop a functional widget. For experienced developers, the material will be a guide to adapting existing solutions to the Xiaomi ecosystem.

πŸ“Š What Xiaomi model are you developing a widget for?
Redmi Note 12/13
Mi 14/13
POCO F5/X5
Another smartphone
Xiaomi tablet

1 What is a widget and why is it needed on Xiaomi

A widget is a miniature app that appears directly on the home screen of a smartphone. Unlike conventional icons, widgets can:

  • πŸ“Š Show real-time data (weather, exchange rate, health statistics).
  • πŸ”§ Offer quick action (turn on flashlight, start timer, manage smart devices).
  • 🎨 Support customization (size, color, display style change).
  • πŸ”„ Update automatically without manual user intervention.

Xiaomi widgets integrated into the shell MIUI, It's a very restrictive system, for example, not all third-party widgets can be displayed correctly on resolution screens. FHD+ or 2K, Some features (like sensor access) require special permissions, but there are more customization options than on Android.

Why should you create widgets specifically for Xiaomi?

  • πŸ“± Big audience: Xiaomi is top-3 Global smartphone sales (counterpoint data for 2023 year).
  • πŸ› οΈ Flexibility MIUI: The shell supports non-standard widget sizes (for example, 4Γ—2 or 2Γ—4).
  • πŸ’‘ Integration with the ecosystem: widgets can interact with Mi Home, Mi Fit and other brand services.

⚠️ Note: Widgets on Xiaomi with MIUI 14+ They can be blocked by the security system if they request permission to access the security system. SMS, Check the Mi Developer Console policy before posting.

2. Tool preparation: what is needed for development

To create a widget for Xiaomi, you will need:

Tool.AppointmentWhere to download
Android Studio (version 2022.3)+)The main development environment for writing widget code and testing it.Official website
Mi Developer AccountNeed to publish the widget in the Mi App Store and get the keys API.dev.mi.com
Xiaomi ADB/Fastboot ToolsUtility for debugging on physical devices (unlocking the bootloader, installation) APK).XDA Developers
Figma or Adobe XDDesign of widget layouts taking into account the guidelines MIUI.figma.com

Before starting work:

  1. Install Android Studio and plugins Kotlin/Java.
  2. Download. MIUI SDK (If you plan to use the functions of the Xiaomi ecosystem).
  3. Register as a developer on the Xiaomi platform (a passport is required for verification).
  4. Connect the test device (Redmi, POCO or Mi) in debugging mode (Settings) β†’ The phone. β†’ Version. MIUI β†’ 7 times tap to activate the developer mode).

Install Android Studio 2022.3+

Download MIUI SDK (if necessary)

Register with Mi Developer Console

Connect the Xiaomi device in debugging mode

Create a new project with a Widget template-->

If you are developing a smart home widget (such as Mi Smart Band or Yeelight), you will need to:

  • πŸ”‘ API-Mi Home Open keys API (Requested in the personal office of the developer).
  • πŸ“‘ Xiaomi MiIo Library for Interaction with MiIo Devices.

⚠️ Attention: On devices with MIUI Globally, some API They can be blocked. Use firmware to test. MIUI China EU ROM (For example, from Xiaomi.eu).

3. Creating a basic widget: Step-by-step

Let's take a simple widget that shows the current date and time, and you can extend that template to a weather informer or task tracker.

Step 1: Creating a project in Android Studio

  1. Start Android Studio and select New Project β†’ Widget.
  2. Please specify the name of the package (e.g. com.example.miwidget).
  3. Select the minimum version of Android 8.1 (API 27) – This ensures compatibility with most Xiaomi devices.

Step. 2. File editing widget_info.xml

This file specifies the widget parameters: size, refresh rate, initial layout. Open it in the folder. res/xml and make changes:

<appwidget-provider


xmlns:android="http://schemas.android.com/apk/res/android"




android:minWidth="110dp"




android:minHeight="40dp"




android:updatePeriodMillis="3600000" <-- Update every 60 minutes -->




android:initialLayout="@layout/widget_layout"




android:resizeMode="horizontal|vertical"




android:widgetCategory="home_screen">




</appwidget-provider>

Step. 3. Design layout (widget_layout.xml)

Use ConstraintLayout or LinearLayout for adaptability. Example code for time display:

<TextView


android:id="@+id/time_text"




android:layout_width="wrap_content"




android:layout_height="wrap_content"




android:textSize="18sp"




android:textColor="#FFFFFF"




android:background="@drawable/widget_background"/>

Step 4: Update logic (MiWidgetProvider.kt file)

Add a code to update the time every minute:

class MiWidgetProvider : AppWidgetProvider() {


override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {




val currentTime = SimpleDateFormat("HH:mm", Locale.getDefault()).format(Date())




val views = RemoteViews(context.packageName, R.layout.widget_layout)




views.setTextViewText(R.id.time_text, currentTime)




appWidgetManager.updateAppWidget(appWidgetIds, views)




}




}

adb install -r app-debug.apk

After installation, add the widget to the main screen manually (long press). β†’ "Widgets").-->

Step 5: Adaptation to MIUI

Shell MIUI It can crop widgets or change their transparency to avoid problems:

  • 🎨 Use a transparent background (android:background)="@android:color/transparent").
  • πŸ“ Specify the dimensions in dp, not px, so that the widget can scale correctly on high-resolution screens (e.g. Mi 13 Ultra).
  • ⚑ Turn off hardware acceleration for TextView if text is displayed blurry (android:layerType)="software").

Extended functions: interactivity and data

The basic widget displays static information, but the real power is unlocked when you add interactivity.

  • πŸ”„ Update tapu data (e.g. weather on request).
  • πŸ“Š Graphs and charts (for fitness trackers or financial widgets).
  • πŸ”— Quick actions (opening the application, calling the function).

Example: Adding an update button

In the file widget_layout.xml add a button:

<Button


android:id="@+id/refresh_button"




android:layout_width="wrap_content"




android:layout_height="wrap_content"




android:text="Update"/>

In the MiWidgetProvider.kt class, process the pressing:

views.setOnClickPendingIntent(


R.id.refresh_button,




PendingIntent.getBroadcast(




context,




0,




Intent(context, MiWidgetProvider::class.java).setAction("REFRESH_ACTION"),




PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE




)




)

Then add the action handler to onReceive:

override fun onReceive(context: Context, intent: Intent) {


super.onReceive(context, intent)




if (intent.action == "REFRESH_ACTION") {




// Logic of data update




}




}

Work with API

If your widget needs to show weather, currency rates or data from the exchange, use third-party API. Example of OpenWeatherMap Request:

suspend fun fetchWeather(apiKey: String, city: String): WeatherData {


val response = Retrofit.Builder()




.baseUrl("https://api.openweathermap.org/data/2.5/")




.build()




.create(WeatherApi::class.java)




.getCurrentWeather(city, apiKey)




return response.body()!!




}

⚠️ Note: Xiaomi blocks network requests in the background for widgets if they consume too much traffic.Use WorkManager for periodic updates instead of persistent requests.

How to get around restrictions MIUI background-process?
For widgets that need to update data frequently (such as cryptocurrency rates), use the Foreground Service with a notification. Alternatively, request an update only when you unlock the screen through BroadcastReceiver for action. android.intent.action.USER_PRESENT.

5. Testing and debugging on Xiaomi devices

Testing on real Xiaomi devices is a critical stage, as emulators do not always correctly simulate behavior. MIUI. Follow the checklist:

Check the display on screens with resolution FHD+ and 2K

Make sure the widget doesn’t crop when you change size

Test the work after restarting the device

Check battery consumption in settings MIUI

Make sure the widget is running in energy saving mode-->

Typical problems and solutions:

Problem.Reason.Decision
The widget is not updatedToo long interval in updatePeriodMillis or lock MIUI.Use AlarmManager to force an update.
Blurred textHardware acceleration or incorrect font size.Add android:layerType="software" or increase textSize.
Widget disappears after MIUI updateThe system resets the widget cache.Implement data backup through SharedPreferences.

To debug, use Logcat in Android Studio with a filter tagged with your widget:

adb logcat | grep "MiWidgetProvider"

Testing on different models

The behavior of the widget may differ by:

  • πŸ“± Redmi Note 12 (AMOLED-screen, MIUI 14).
  • πŸ“± POCO X5 (120Hz, Aggressive Battery Optimization).
  • πŸ“± Mi 13 Ultra (High Resolution, Always-on Display Support).

It is recommended to test at least 2-3 devices with different versions. MIUI. If you don’t have physical devices, use Xiaomi. EU ROM emulator.

6.Publishing the widget in the Mi App Store

To make your widget available to other Xiaomi users, publish it in the official Mi App Store.

Step 1: Preparation of materials

  • πŸ“ Description in Chinese and English (required!).
  • πŸ–ΌοΈ Screenshots (permission at least) 1080Γ—1920).
  • πŸŽ₯ Demo video (optional, but increases the chances of approval).
  • πŸ“„ APK-file (signed with release key).

Step 2: Download to Mi Developer Console

  1. Sign in to dev.mi.com.
  2. Go to the App Release section β†’ New App.
  3. Fill in the metadata (name, category, supported devices).
  4. Download. APK materials.

Step 3: Moderation

The review period is 3 to 7 days, and the reasons for the rejection are:

  • 🚫 The widget requests unnecessary permissions (e.g, READ_SMS weather-informant).
  • 🚫 Hydeline breach MIUI (For example, using the Xiaomi logo without permission).
  • 🚫 Unstable work on test devices of moderators.

⚠️ Note: Xiaomi charges 30% fee for paid widgets and subscriptions (similar to Google Play) Free apps are published without commission, but with restrictions on monetization (for example, hidden payments through third-party services are prohibited).

Alternative means of distribution

If moderation in the Mi App Store is delayed, consider:

  • 🌐 Google Play (Widget will be available on all Android devices, but without optimization for Android devices) MIUI).
  • πŸ“¦ APK-forum-file (XDA Developers, 4PDA).
  • πŸ”— Telegram bot for distribution among test groups.

7. Optimization and promotion of the widget

Even the most useful widget will go unnoticed without proper promotion.

Technical optimization

  • ⚑ Reduce battery consumption: Use WorkManager instead of constant background processes.
  • πŸ“¦ Reduce the size APK: Remove unnecessary libraries (e.g. Play Services if you are not using Google) API).
  • πŸ› οΈ Adapt to a dark theme MIUI: <style name="WidgetTheme" parent="Theme.AppCompat.DayNight"> <item name="android:textColor">?android:attr/textColorPrimary</item> </style>

Marketing strategies

  • πŸ“’ Create a promotional page on GitHub or Product Hunt.
  • πŸ“Ή Record a review for YouTube (channels like TechDroider often highlight new widgets).
  • πŸ’¬ Collaborate with bloggers who write about customization MIUI.

Monetization

If the widget solves a narrow problem (e.g., managing the Mi Band or displaying Mi Fit statistics), consider the models:

  • πŸ’° Paid version with advanced functions.
  • β˜• Donations via Patreon or Buy Me a Coffee.
  • πŸ“¦ Subscription to premium content (e.g., advanced themes).

πŸ’‘

Widgets integrated with Xiaomi’s ecosystem (smart home, fitness trackers) have a 40% higher chance of being approved in the Mi App Store and are better monetized.

FAQ: Frequent questions about creating widgets for Xiaomi

Can you create a widget without programming knowledge?
Technically yes, with the help of designers. KWGT (Kustom Widget Maker or UCCW. However, such widgets will be limited in functionality and will not be able to interact with the user. API Xiaomi or third-party services. Kotlin/Java.
Why is my widget not updated on Xiaomi?
The reasons may be different: MIUI Optimizes the battery: add the widget to exceptions (Settings) β†’ Battery β†’ Battery optimization? Too long refresh interval: in widget_info.xml UpdatePeriodMillis update="1800000" (30 Errors in code: check Logcat for exceptions.
How to make a widget with a transparent background for MIUI?
Add in. widget_layout.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@android:color/transparent" android:layout_width="match_parent" android:layout_height="match_parent"> </LinearLayout> If the background is still not transparent, check if the styles in the topic are overdetermined. MIUI.
Can I make money on widgets for Xiaomi?
Yes, but revenue is niche-dependent: Weather widgets: low monetization due to high competition. Smart home widgets (Mi Home, Yeelight): high monetization, as the audience is willing to pay for convenience. Niche solutions (for example, for traders or gamers): average monetization, but loyal audience: Average revenue per user on the Mi App Store β€” $0.1–$0.5 per month (for paid functions).
How to test a widget on Xiaomi without a physical device?
Options: Emulator with Xiaomi EU ROM: Download the image from Xiaomi.eu and install it through Android Studio. Remote testing: services like BrowserStack or Firebase Test Lab support Xiaomi devices. APK forum-wise (4PDA, XDA) And you can get feedback, and notice that emulators don't always mimic behavior correctly. MIUI, Especially in terms of battery optimization.