如何以编程方式关闭运行时权限对话框? [英] How to close runtime permission dialog programmatically?

查看:127
本文介绍了如何以编程方式关闭运行时权限对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要实现一个场景,在该场景中,用户闲置5秒钟后必须关闭拒绝"运行时权限对话框.

We need to implement a scenario where we have to close runtime permission dialog with Denial after 5 seconds of inactivity of user.

步骤:

  1. 用户单击保存"按钮

  1. User clicks the Save button

权限对话框.

如果用户5秒钟内未点击接受/拒绝

If user doesn't click accept/deny in 5 seconds

预期结果:应关闭该对话框,并选择拒绝"作为选择.

Expected Result: Dialog should be closed with deny as selected option.

任何帮助将不胜感激.

还请让我知道,是否有可能这样做?

Also please let me know that if this is even possible to do so or not ?

推荐答案

这确实是有效的边缘情况,如下所述.

This is indeed a valid edge case, as explained below.

sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

为什么要关闭权限对话框?

假设用户启动了您的应用,并立即显示了权限对话框,例如从一个片段.然后,用户切换到另一个应用,新的意图从该应用发送到您的应用,例如Intent.ACTION_VIEW.然后,您可能需要在显示权限对话框之前更改/重新布置UI:

Why close the permission dialog?

Let's say the user starts your app and the permission dialog is immediately shown, e.g. from a fragment. Then the user switches to another app from which a new intent is sent to your app, e.g. Intent.ACTION_VIEW. Then you might want to change/rearrange the UI before showing the permission dialog:

protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    if (isShowingPermissionDialog() {
        // Handle this intent after permisson dialog is dismissed!
        mPendingIntent = intent;
    } else {
        // This could interfere with the expected permission
        // callback of the active fragment etc.
        changeActiveFragment();
    }
}

或者,如果您想显式关闭权限对话框:

Or, if you instead want to explicitly close the permission dialog:

private void closeSystemDialogs() {
    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}

protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    closeSystemDialogs();

    changeActiveFragment();
}

这篇关于如何以编程方式关闭运行时权限对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆