Launch an Android app on top of the lock screen

I am trying to create an alarm clock that plays a Youtube video at a specific time. When I use wakelock, it plays a Youtube video behind a locked screen using this code:

PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "")

I would like the application to wake the phone and play Youtube video in front of the lock screen, for example, the native alarm application ringing in front of the locked screen.

Does anyone know how to do this? Thanks!

+4
source share
2 answers

You can create a system overlay and play the video on it. Create a service and add this code:

@Override
    public void onCreate() {
        super.onCreate();
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
               |WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,
                PixelFormat.TRANSLUCENT);
        params.gravity = Gravity.RIGHT | Gravity.TOP;
        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        wm.addView(yourView, params);
    }

Remember to add SYSTEM_ALERT_WINDOWpermission inside the manifest.

EDIT. TYPE_SYSTEM_ALERT TYPE_SYSTEM_ERROR TYPE_SYSTEM_OVERLAY.

+4

, , , onCreate:

this.getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                        | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                        | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                        | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+1

All Articles