11package com .rexraphael .flutterunitywidget ;
22
33import android .app .Activity ;
4+ import android .content .ContextWrapper ;
45import android .graphics .PixelFormat ;
56import android .os .Build ;
67import android .view .ViewGroup ;
@@ -48,13 +49,8 @@ public static void createPlayer(final Activity activity, final CreateCallback ca
4849 @ Override
4950 public void run () {
5051 activity .getWindow ().setFormat (PixelFormat .RGBA_8888 );
51- int flag = activity .getWindow ().getAttributes ().flags ;
52- boolean fullScreen = false ;
53- if ((flag & WindowManager .LayoutParams .FLAG_FULLSCREEN ) == WindowManager .LayoutParams .FLAG_FULLSCREEN ) {
54- fullScreen = true ;
55- }
5652
57- unityPlayer = new UnityPlayer (activity );
53+ unityPlayer = new UnityPlayer (( ContextWrapper ) activity . getApplicationContext () );
5854
5955 try {
6056 // wait a moument. fix unity cannot start when startup.
@@ -63,16 +59,11 @@ public void run() {
6359 }
6460
6561 // start unity
66- addUnityViewToBackground ();
62+ addUnityViewToBackground (activity );
6763 unityPlayer .windowFocusChanged (true );
6864 unityPlayer .requestFocus ();
6965 unityPlayer .resume ();
7066
71- // restore window layout
72- if (!fullScreen ) {
73- activity .getWindow ().addFlags (WindowManager .LayoutParams .FLAG_FORCE_NOT_FULLSCREEN );
74- activity .getWindow ().clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
75- }
7667 _isUnityReady = true ;
7768 callback .onReady ();
7869 }
@@ -120,7 +111,7 @@ public static void removeUnityEventListener(UnityEventListener listener) {
120111 mUnityEventListeners .remove (listener );
121112 }
122113
123- public static void addUnityViewToBackground () {
114+ public static void addUnityViewToBackground (final Activity activity ) {
124115 if (unityPlayer == null ) {
125116 return ;
126117 }
@@ -130,7 +121,6 @@ public static void addUnityViewToBackground() {
130121 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
131122 unityPlayer .setZ (-1f );
132123 }
133- final Activity activity = ((Activity )unityPlayer .getContext ());
134124 ViewGroup .LayoutParams layoutParams = new ViewGroup .LayoutParams (1 , 1 );
135125 activity .addContentView (unityPlayer , layoutParams );
136126 }
0 commit comments