android 中 FLAG_SHOW_WHEN_LOCKED 的用法及解釋

如何讓一個activity 浮在鎖屏界面的上方,返回即進入解鎖界面。
譬如在鎖屏界面,來電時是不需要先解鎖才能接聽電話的。這樣能帶來快捷。
如果你想在android 上實現 iphone 4s 上面在鎖屏界面就能進照相機的話也可以按此方式來進行。
隻需要在 Camera 的 activity 的 onResume 函數中添加如下 flag 即可實現。

import android.view.Window;
import android.view.WindowManager;

final Window win = activity.getWindow();
final WindowManager.LayoutParams params = win.getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;

        /** Window flag: special flag to let windows be shown when the screen
         * is locked. This will let application windows take precedence over
         * key guard or any other lock screens. Can be used with
         * {@link #FLAG_KEEP_SCREEN_ON} to turn screen on and display windows
         * directly before showing the key guard window.  Can be used with
         * {@link #FLAG_DISMISS_KEYGUARD} to automatically fully dismisss
         * non-secure keyguards.  This flag only applies to the top-most
         * full-screen window.
         */
        public static final int FLAG_SHOW_WHEN_LOCKED = 0x00080000

You May Also Like