FLAG_DISMISS_KEYGUARD不再工作在Android棒棒糖?棒棒糖、工作、FLAG_DISMISS_KEYGUARD、Android

2023-09-05 10:43:10 作者:一生难拥友

正如标题所说,我一直惊讶地发现,FLAG_DISMISS_KEYGUARD标志不再API 21(棒棒堂)工作。

As the title says, I've been surprised to find that FLAG_DISMISS_KEYGUARD flag is no longer functioning on API 21 (Lollipop).

在奇巧,设置此标志将解除不安全的键盘锁。

In kitkat, setting this flag would dismiss an insecure keyguard.

所以这是一个功能或一个错误?有什么解决办法?

So is this a feature or a bug? What's the workaround?

通过电源管理器类禁用键盘锁是一种选择,但它不能正常工作像解雇的风格。可以吗?

Disabling keyguard via PowerManager class is an option, but it can't work like dismissal style. Can it?

推荐答案

第一:这是一个错误

二,是否有解决方法吗?是的。

Second, Is there a workaround? Yes.

由于我stumpled在这个问题上,甚至谷歌不知道这个问题, 我就如何解决这个巨大的研究。 这是很容易的。该缺陷是键盘锁被注册了两个presumably 次机器人实习生。

Because I stumpled upon this issue and even google did not know this issue, I made a tremendous research on how to work around this. It's quite easy. The bug is presumably that the keyguard is registered two times android intern.

关键是要启动的 pre运行的正手在活动,听 屏幕上播放,驳回键盘锁,并开始你的真实intented 活动。

The trick is to start a pre running activity in forehand, listening to screen on broadcasts, dismissing the keyguard and start your real intented activity.

code:

public class KeyGuardDismissActivity extends Activity {

    private ScreenOnReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LOG.d("Start keyguard dismisser!");
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            startActivity(new SomeOtherActivityIntent(getApplicationContext()));
            finish();
            return;
        }
        this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        receiver = new ScreenOnReceiver();
        registerReceiver(receiver, receiver.getFilter());
    }

    private void dismissingKeyguard() {
        LOG.d("Dismissing keyguard!");
        SomeOtherActivityIntent yourRealActivity = new SomeOtherActivityIntent(getApplicationContext(), this);
        startActivity(yourRealActivity );
        if (receiver != null) {
            unregisterReceiver(receiver);
        }
        finish();
    }

    private class ScreenOnReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            LOG.d("Screen on, yay!");
            dismissingKeyguard();
        }

        public IntentFilter getFilter() {
            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_SCREEN_ON);
            return filter;
        }
    }
}

您的真实活动中,你必须添加驳回标志呢!

问候。

 
精彩推荐
图片推荐