Reputation: 1520
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?
Upvotes: 16
Views: 3620
Reputation: 1104
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)
}
}
Upvotes: 5
Reputation: 1117
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
}
}
Upvotes: 2
Reputation: 119
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)
}
Upvotes: 2
Reputation: 623
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.
Upvotes: 9