Enable "Show on Lock Screen " permission on Redmi device
Asked Answered
G

4

14

I have an android app which is voip app. When some one call we show a caller screen. This works fine but on some redmi device(Note 7 pro) the caller screen doesn't come if device is locked ie it only play sound.

On debugging I found I need to enable "Show on Lock Screen" permission for the device. Once I enable it it start working as expected. My issue is, I want to improve UI experience by checking this permission at run-time programmatically but unfortunately I am not able to find any thing which can allow me to check this. Is it possible on Redmi device?

Grenier answered 24/1, 2020 at 9:6 Comment(4)
Did you find any solution?Hildagarde
No. We ended up letting user do it manually.Grenier
is there any solution for this yet ?Fatherless
I found many apps enable the permission programmatically - refer vyng app for xiaomiLarcenous
F
6

As someone who works on Glance (Wallpaper Carousel), which is a product placed on the lock screen of Xiaomi devices, this permission is granted only by Xiaomi. This permission by default is only granted to a set of pre-bundled apps and to get this you need to get your app whitelisted by having it added it to the priv-permission allowlist by Xiaomi.

Flagellum answered 8/11, 2021 at 20:11 Comment(0)
C
1

You can try below code, it may help you to solve problem.

if (Build.MANUFACTURER.equals("Xiaomi",true)) {
        val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
        intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity")
        intent.putExtra("extra_pkgname", packageName)
        startActivity(intent)
    }
Cotidal answered 16/1, 2023 at 17:2 Comment(0)
E
1

Use the Below code to check weather lock screen permission is given or not?

private fun isShowOnLockScreenPermissionEnable(): Boolean {
        return try {
            val manager = context.getSystemService(APP_OPS_SERVICE) as AppOpsManager
            val method: Method = AppOpsManager::class.java.getDeclaredMethod(
                "checkOpNoThrow",
                Int::class.javaPrimitiveType,
                Int::class.javaPrimitiveType,
                String::class.java
            )
            val result =
                method.invoke(manager, 10020, Binder.getCallingUid(), context.packageName) as Int
            AppOpsManager.MODE_ALLOWED == result
        } catch (e: Exception) {
            false
        }
    }

and now use the below code to navigate the user to permission screen

if(isShowOnLockScreenPermissionEnable()){
            Toast.makeText(this, "Permission is already granted!!", Toast.LENGTH_SHORT).show()
        }else{
            if (Build.MANUFACTURER.equals("Xiaomi", true)) {
                val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
                intent.setClassName(
                    "com.miui.securitycenter",
                    "com.miui.permcenter.permissions.PermissionsEditorActivity"
                )
                intent.putExtra("extra_pkgname", packageName)
                startActivity(intent)
            }
        }
Educationist answered 22/5, 2023 at 12:1 Comment(0)
V
0

same here, I can only show how to check this permission:

    private fun isShowOnLockScreenPermissionEnable(): Boolean? {
    return try {
        val manager = context.getSystemService(APP_OPS_SERVICE) as AppOpsManager
        val method: Method = AppOpsManager::class.java.getDeclaredMethod(
            "checkOpNoThrow",
            Int::class.javaPrimitiveType,
            Int::class.javaPrimitiveType,
            String::class.java
        )
        val result = method.invoke(manager, 10020, Binder.getCallingUid(), context.packageName) as Int
        AppOpsManager.MODE_ALLOWED == result
    } catch (e: Exception) {
        null
    }
}
Vernitavernoleninsk answered 15/2, 2023 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.