How to Show Permission Prompt or Redirect to 'Other Permissions' for Background Pop-up Windows on Xiaomi Devices (Custom Shortcuts Launcher)

Xiaomi devices, powered by MIUI (Xiaomi’s custom Android skin), offer enhanced security and battery optimization features. However, these features can sometimes restrict app functionality—especially for background pop-up windows, a common requirement for apps like custom shortcuts launchers, productivity tools, or notification managers.

If your app displays floating windows, alerts, or custom UI elements when running in the background (e.g., a shortcut launcher showing a quick-action menu), Xiaomi’s MIUI may block these pop-ups by default. This is due to a MIUI-specific permission called "Display pop-up windows while running in the background", tucked away in the "Other Permissions" section of app settings.

This blog will guide developers through:

  • Understanding MIUI’s unique permission model for background pop-ups.
  • Detecting Xiaomi devices programmatically.
  • Checking if the required permission is granted.
  • Redirecting users to the "Other Permissions" settings to enable the permission.

By the end, you’ll ensure your custom shortcuts launcher (or any app using background pop-ups) works seamlessly on Xiaomi devices.

Table of Contents#

  1. Understanding the Problem: Background Pop-ups on Xiaomi Devices
  2. MIUI’s Permission Ecosystem: Where to Find "Background Pop-up" Permissions
  3. Detecting Xiaomi Devices Programmatically
  4. Checking if "Background Pop-up" Permission is Granted
  5. Redirecting to "Other Permissions" Settings
  6. Implementing the Full Flow: Check → Detect → Redirect
  7. Troubleshooting Common Issues
  8. Best Practices for User Experience
  9. Conclusion
  10. References

1. Understanding the Problem: Background Pop-ups on Xiaomi Devices#

On stock Android, apps can display floating windows using the SYSTEM_ALERT_WINDOW permission (declared in the manifest and granted via the "Display over other apps" setting). However, Xiaomi’s MIUI adds an extra layer of restriction: even if SYSTEM_ALERT_WINDOW is granted, background pop-ups (when the app is not in the foreground) may still be blocked unless a specific MIUI-only permission is enabled.

This permission is:
"Display pop-up windows while running in the background"

Without it, your app’s pop-ups (e.g., a shortcut menu triggered from the launcher) will fail to appear when the app is in the background, leading to a broken user experience.

2. MIUI’s Permission Ecosystem: Where to Find "Background Pop-up" Permissions#

MIUI organizes app permissions into categories like "Permissions" (standard Android permissions) and "Other permissions" (MIUI-specific or advanced permissions). The "Background Pop-up" permission lives in the latter.

To manually enable it (for testing):

  1. Open Settings on the Xiaomi device.
  2. Go to Apps → Select your app (e.g., "Custom Launcher").
  3. Tap Other permissions (usually below "Permissions" and "Battery saver").
  4. Look for "Display pop-up windows while running in the background" and toggle it on.

Your goal is to guide users to this exact screen programmatically.

3. Detecting Xiaomi Devices Programmatically#

You only need to apply these fixes to Xiaomi devices. Use the following code to detect Xiaomi hardware and MIUI software:

Step 1: Check Manufacturer (Xiaomi)#

Android’s Build class reveals the device manufacturer. Xiaomi devices return Build.MANUFACTURER = "Xiaomi".

// Kotlin
val isXiaomi = Build.MANUFACTURER.equals("Xiaomi", ignoreCase = true)
// Java
boolean isXiaomi = "Xiaomi".equalsIgnoreCase(Build.MANUFACTURER);

Some devices may have Xiaomi hardware but non-MIUI software (e.g., Android One). To confirm MIUI, check for MIUI-specific system properties:

// Kotlin: Check for MIUI using system properties
fun isMiui(): Boolean {
    return try {
        val prop = Class.forName("android.os.SystemProperties")
            .getMethod("get", String::class.java)
            .invoke(null, "ro.miui.ui.version.name") as String? != null
    } catch (e: Exception) {
        false
    }
}

Combine both checks to target Xiaomi MIUI devices exclusively.

4. Checking if "Background Pop-up" Permission is Granted#

MIUI does not expose this permission via standard Android APIs (e.g., checkSelfPermission). Instead, we use AppOpsManager (Android’s hidden permission management system) to check if the permission is enabled.

The MIUI-specific AppOps operation code for background pop-ups is OP_BACKGROUND_WINDOW (code 24). Use this to check permission status:

Code to Check Permission Status#

// Kotlin
fun hasBackgroundPopUpPermission(context: Context): Boolean {
    val appOps = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
    val packageName = context.packageName
    val uid = context.applicationInfo.uid
 
    return try {
        // Check AppOps for OP_BACKGROUND_WINDOW (MIUI-specific)
        val mode = appOps.checkOpNoThrow(
            24, // OP_BACKGROUND_WINDOW (MIUI code for background pop-ups)
            uid,
            packageName
        )
        mode == AppOpsManager.MODE_ALLOWED
    } catch (e: Exception) {
        // Fallback: Assume permission is denied if check fails
        false
    }
}

Note: OP_BACKGROUND_WINDOW is not documented, so test on multiple MIUI versions (12–15) to ensure compatibility. If the check fails (e.g., on newer MIUI versions), treat it as "permission denied" and prompt the user.

5. Redirecting to "Other Permissions" Settings#

If the permission is denied, redirect the user to the "Other Permissions" page for your app. MIUI does not provide a direct intent for this page, but we can use two approaches:

Approach 1: Direct Intent to "Other Permissions" (MIUI-Specific)#

Some MIUI versions support a direct intent to launch the "Other Permissions" screen. Use this first, as it’s more user-friendly:

// Kotlin: Intent to open "Other Permissions" (MIUI-specific)
fun getOtherPermissionsIntent(packageName: String): Intent? {
    return try {
        Intent().apply {
            action = "miui.intent.action.APP_PERM_EDITOR"
            setClassName(
                "com.miui.securitycenter", 
                "com.miui.permcenter.permissions.PermissionsEditorActivity"
            )
            putExtra("extra_pkgname", packageName)
            flags = Intent.FLAG_ACTIVITY_NEW_TASK
        }
    } catch (e: Exception) {
        null // Fallback to app info if intent fails
    }
}

Approach 2: Fallback to App Info Page#

If the MIUI-specific intent fails (e.g., on older MIUI versions), redirect to the app’s "App Info" page. From there, users can navigate to "Other Permissions":

// Kotlin: Intent to open App Info page (fallback)
fun getAppInfoIntent(packageName: String): Intent {
    return Intent(
        Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
        Uri.fromParts("package", packageName, null)
    ).apply {
        flags = Intent.FLAG_ACTIVITY_NEW_TASK
    }
}

6. Implementing the Full Flow: Check → Detect → Redirect#

Combine device detection, permission checking, and redirection into a seamless flow. Here’s how to implement it in your custom shortcuts launcher:

Step 1: Trigger the Check Before Showing a Background Pop-up#

Call this method when the user triggers a feature requiring a background pop-up (e.g., tapping a custom shortcut):

// Kotlin
fun showBackgroundPopUp(context: Context) {
    // Only run on Xiaomi MIUI devices
    if (isXiaomi && isMiui()) {
        if (!hasBackgroundPopUpPermission(context)) {
            // Permission denied: Show dialog to redirect to settings
            showPermissionPromptDialog(context)
            return
        }
    }
 
    // Permission granted: Show your pop-up
    showYourPopUpWindow()
}

Step 2: Show a User-Friendly Dialog#

Explain why the permission is needed and guide the user to enable it:

// Kotlin: Show dialog to request permission
private fun showPermissionPromptDialog(context: Context) {
    AlertDialog.Builder(context)
        .setTitle("Enable Background Pop-ups")
        .setMessage("To show shortcuts while your app is in the background, enable 'Display pop-up windows while running in the background' in Settings.")
        .setPositiveButton("Go to Settings") { _, _ ->
            redirectToOtherPermissions(context)
        }
        .setNegativeButton("Cancel", null)
        .show()
}

Step 3: Redirect to Settings#

Use the MIUI intent first, falling back to App Info if needed:

// Kotlin: Redirect to "Other Permissions" or App Info
private fun redirectToOtherPermissions(context: Context) {
    val packageName = context.packageName
    // Try MIUI-specific "Other Permissions" intent first
    val miuiIntent = getOtherPermissionsIntent(packageName)
    if (miuiIntent != null && context.packageManager.resolveActivity(miuiIntent, 0) != null) {
        context.startActivity(miuiIntent)
    } else {
        // Fallback to App Info page
        context.startActivity(getAppInfoIntent(packageName))
        // Show a toast guiding the user from App Info to Other Permissions
        Toast.makeText(
            context,
            "Tap 'Other permissions' → Enable 'Display pop-up windows while running in the background'",
            Toast.LENGTH_LONG
        ).show()
    }
}

6. Implementing the Full Flow: Check → Detect → Redirect#

Combine device detection, permission checking, and redirection into a seamless flow. Here’s how to implement it in your custom shortcuts launcher:

Step 1: Trigger the Check Before Showing a Background Pop-up#

Call this method when the user triggers a feature requiring a background pop-up (e.g., tapping a custom shortcut):

// Kotlin
fun showBackgroundPopUp(context: Context) {
    // Only run on Xiaomi MIUI devices
    if (isXiaomi && isMiui()) {
        if (!hasBackgroundPopUpPermission(context)) {
            // Permission denied: Show dialog to redirect to settings
            showPermissionPromptDialog(context)
            return
        }
    }
 
    // Permission granted: Show your pop-up
    showYourPopUpWindow()
}

Step 2: Show a User-Friendly Dialog#

Explain why the permission is needed and guide the user to enable it:

// Kotlin: Show dialog to request permission
private fun showPermissionPromptDialog(context: Context) {
    AlertDialog.Builder(context)
        .setTitle("Enable Background Pop-ups")
        .setMessage("To show shortcuts while your app is in the background, enable 'Display pop-up windows while running in the background' in Settings.")
        .setPositiveButton("Go to Settings") { _, _ ->
            redirectToOtherPermissions(context)
        }
        .setNegativeButton("Cancel", null)
        .show()
}

Step 3: Redirect to Settings#

Use the MIUI intent first, falling back to App Info if needed:

// Kotlin: Redirect to "Other Permissions" or App Info
private fun redirectToOtherPermissions(context: Context) {
    val packageName = context.packageName
    // Try MIUI-specific "Other Permissions" intent first
    val miuiIntent = getOtherPermissionsIntent(packageName)
    if (miuiIntent != null && context.packageManager.resolveActivity(miuiIntent, 0) != null) {
        context.startActivity(miuiIntent)
    } else {
        // Fallback to App Info page
        context.startActivity(getAppInfoIntent(packageName))
        // Show a toast guiding the user from App Info to Other Permissions
        Toast.makeText(
            context,
            "Tap 'Other permissions' → Enable 'Display pop-up windows while running in the background'",
            Toast.LENGTH_LONG
        ).show()
    }
}

7. Troubleshooting Common Issues#

IssueFix
MIUI intent fails to launch "Other Permissions"Fall back to the App Info page and use a toast to guide users to "Other Permissions."
OP_BACKGROUND_WINDOW check returns incorrect resultsTest on MIUI 12–15. If the check is unreliable, skip it and always prompt Xiaomi users (if background pop-ups are critical).
User denies permission repeatedlyAdd a "Don’t ask again" checkbox in the dialog, and disable features requiring the permission if unchecked.
Pop-ups still blocked after permission is enabledEnsure SYSTEM_ALERT_WINDOW is also granted (declare <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> in AndroidManifest.xml).

8. Best Practices for User Experience#

  • Explain "Why" the Permission is Needed: Users are more likely to enable permissions if they understand the benefit (e.g., "Enable this to see shortcut menus when using other apps").
  • Use Screenshots: In the dialog, include a small image showing the "Display pop-up windows while running in the background" toggle (use ImageView in the dialog layout).
  • Test on Real Devices: MIUI varies across Xiaomi models (e.g., Redmi vs. POCO). Test on low-end and high-end devices.
  • Post-Redirect Confirmation: After redirecting, check the permission again when the user returns to your app. If enabled, show a success message; if not, prompt again.

9. Conclusion#

Xiaomi’s MIUI adds unique challenges for apps using background pop-ups, but with the right detection, permission checks, and redirection logic, you can ensure your custom shortcuts launcher works flawlessly. By guiding users to the "Other Permissions" settings and explaining the value of the permission, you’ll minimize friction and keep users engaged.

10. References#

Let me know in the comments if you need help adapting this flow to your specific app! 🚀