Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
408 views
in Technique[技术] by (71.8m points)

android - How to start a dialog (like alarm dimiss /snooze) that can be clicked without unlocking the screen

I dont want to permanently bypass keyguard, just for that moment .For example when a alarm is raised (eg wake up alarm) i can dismiss /snooze it whithout unlocking screen .I want to achive the same behaviour.I want start a dialog which should be on top on locked screen. I can click button on dialog without unlocking .Is this possible ?If yes how?

I dont want the following :

private void unlockScreen(Context context){
        Log.d("dialog", "unlocking screen now");
        PowerManager powermanager = ((PowerManager)context.getSystemService(Context.POWER_SERVICE));
        WakeLock wakeLock = powermanager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
        wakeLock.acquire();
        Window wind = DialogActivity.this.getWindow();
        wind.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
        wind.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        wind.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);


    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

May be this will useful. Implement window flag FLAG_SHOW_WHEN_LOCKED along with FLAG_TURN_SCREEN_ON in public WindowManager.LayoutParams ()

or you can use KeyguardManager class( is deprecated in API 13, but still works) by

public KeyguardManager.KeyguardLock newKeyguardLock (String tag)

Use FLAG_DISMISS_KEYGUARD and/or FLAG_SHOW_WHEN_LOCKED instead; this allows you to seamlessly hide the keyguard as your application moves in and out of the foreground and does not require that any special permissions be requested. Enables you to lock or unlock the keyboard. Get an instance of this class by calling Context.getSystemService(). This class is wrapped by KeyguardManager.


WindowManager.LayoutParams


KeyguardManager


Hope you understand now, however feel free to ask if you need more detailed coding instructions for this problem
Cheers..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...