Permission to display pop-up windows while running in the background
Asked Answered
H

2

11

I have a project that needs to display pop-up windows while running in the background permission. How to ask the user permission. I already tried the Setting.canDrawOverlay() but it doesn't work for the app that killed.

this is my app permission in setting

I only can get the green one permission but I need the red one.

Thanks.

Hymenopteran answered 26/11, 2019 at 13:17 Comment(7)
got any solution ?Liverish
did you solved this?Vegetal
@Liverish no yet. still unsolved for meHymenopteran
got any solution I am facing this weird problem in Xiaomi 9t pro device I have to give manually this permissionAlaska
same for me on xiaomi 9 SEHymenopteran
@KevinFarel you got any solution to check permission is granted or not? I am talking for red mark permission which in imageVastah
@NabinDhakal https://mcmap.net/q/1025043/-permission-to-display-pop-up-windows-while-running-in-the-backgroundMacilroy
A
6

This permission has to be given manually, but after searching for some time I came up with an idea that can be used to open the correct permission screen, so the user can activate the permission.

    fun isMiUi(): Boolean {
        return getSystemProperty("ro.miui.ui.version.name")?.isNotBlank() == true
    }

    fun isMiuiWithApi28OrMore(): Boolean {
        return isMiUi() && Build.VERSION.SDK_INT >= 28
    }

    fun goToXiaomiPermissions(context: Context) {
        val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
        intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity")
        intent.putExtra("extra_pkgname", context.packageName)
        context.startActivity(intent)
    }

    private fun getSystemProperty(propName: String): String? {
        val line: String
        var input: BufferedReader? = null
        try {
            val p = Runtime.getRuntime().exec("getprop $propName")
            input = BufferedReader(InputStreamReader(p.inputStream), 1024)
            line = input.readLine()
            input.close()
        } catch (ex: IOException) {
            return null
        } finally {
            if (input != null) {
                try {
                    input.close()
                } catch (e: IOException) {
                    e.printStackTrace()
                }
            }
        }
        return line
    }

In my project I verify if isMiuiWithApi28OrMore() and if it is then I can prepare an additional step telling the user that the app needs the permission and sends him to the permission screen.

I hope it helps.

Ansermet answered 20/2, 2020 at 13:30 Comment(1)
But how to check if permission has already given?Cardiovascular
E
0

This is common problem with xiaomi devices

canDrawOverlay permission seems not to be enough for xiaomi

try this:

if (!Settings.canDrawOverlays(this)) {
            if ("xiaomi".equals(Build.MANUFACTURER.toLowerCase(Locale.ROOT))) {
                final Intent intent =new Intent("miui.intent.action.APP_PERM_EDITOR");
                intent.setClassName("com.miui.securitycenter",
                        "com.miui.permcenter.permissions.PermissionsEditorActivity");
                intent.putExtra("extra_pkgname", getPackageName());
                new AlertDialog.Builder(this)
                        .setTitle("Please Enable the additional permissions")
                        .setMessage("You will not receive notifications while the app is in background if you disable these permissions")
                        .setPositiveButton("Go to Settings", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                startActivity(intent);
                            }
                        })
                        .setIcon(android.R.drawable.ic_dialog_info)
                        .setCancelable(false)
                        .show();
            }else {
                Intent overlaySettings = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
                startActivityForResult(overlaySettings, OVERLAY_REQUEST_CODE);
            }
Erastes answered 21/11, 2021 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.