How to show a FlutterActivity above Android lock screen with visible video playback?


I have a Flutter Android app and I need to show a video screen above the Android lock screen.

The app is a Flutter project. The main screen is a FlutterActivity, and video playback inside Flutter works normally when the app is open.

My goal:

User locks the device / screen turns off
After a few seconds my app opens above the lock screen
A video is visible and playing
When the user taps the video, my UI handles the tap

What I've tried:

(1) When I use a native Android SDK Activity with a native SurfaceView / MediaPlayer, the video is visible above the lock screen more reliably.

(2) With Flutter SDK, I tried using Android lock-screen flags on an Activity:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
    setShowWhenLocked(true)
    setTurnScreenOn(true)
}

window.addFlags(
    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON or
        WindowManager.LayoutParams.FLAG_FULLSCREEN
)

I can start an Activity above the lock screen using a full-screen notification / setFullScreenIntent.

However, when the Activity is a FlutterActivity, the behavior is unreliable:

  • audio from the video can be heard;

  • the video seems to be playing;

  • but the screen is black, or the system lock screen stays above it;

  • after pressing the power/unlock button, the video sometimes becomes visible.

Question:

Is it possible to reliably display a FlutterActivity above the Android lock screen with visible Flutter video rendering?

1
Jul 23 at 11:49 AM
User AvatarAlex20280
#android#flutter#video#android-activity#media-player

No answer found for this question yet.