【问题标题】:Permission to display pop-up windows while running in the background在后台运行时显示弹出窗口的权限
【发布时间】:2023-04-06 02:31:02
【问题描述】:

我有一个项目需要在后台运行时显示pop-up 窗口permission。如何询问用户permission。我已经尝试了Setting.canDrawOverlay(),但它不适用于杀死的应用程序。

this is my app permission in setting

我只能获得绿色的权限,但我需要红色的权限。

谢谢。

【问题讨论】:

  • 有什么解决办法吗?
  • 你解决了吗?
  • @Rahul 还没有。对我来说仍然没有解决
  • 得到任何解决方案我在小米 9t pro 设备中遇到这个奇怪的问题我必须手动授予此权限
  • 我在小米 9 SE 上也一样

标签: android android-permissions


【解决方案1】:

这个权限必须手动给,但是找了一段时间想出了一个思路,可以用来打开正确的权限界面,让用户激活权限。

    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
    }

在我的项目中,我验证是否isMiuiWithApi28OrMore(),如果是,那么我可以准备一个额外的步骤,告诉用户应用程序需要权限并将他发送到权限屏幕。

希望对你有帮助。

【讨论】:

    【解决方案2】:

    这是小米设备的常见问题

    canDrawOverlay 权限似乎对小米来说还不够

    试试这个:

    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);
                }
    

    【讨论】:

      猜你喜欢
      • 2020-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多