Finally, I got a solution.
MainActivity should be expanded as Activity , not UnityPlayerActivity .- Add these two lines to the activity in the android manifest.
<meta-data android:name="unityplayer.UnityActivity" android:value="true" /> <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
Work code:
public class MainActivity extends Activity implements OnTouchListener { public static Context mContext; private Handler handler=new Handler(); protected UnityPlayer mUnityPlayer; protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); mContext = this; getWindow().takeSurface(null); setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); getWindow().setFormat(PixelFormat.RGB_565); mUnityPlayer = new UnityPlayer(this); if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true)) getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1); boolean trueColor8888 = false; mUnityPlayer.init(glesMode, trueColor8888); View playerView = mUnityPlayer.getView(); setContentView(R.layout.activity_main); FrameLayout layout = (FrameLayout) findViewById(R.id.frameLayout2); LayoutParams lp = new LayoutParams (750, 630); layout.addView(playerView, 0, lp); } protected void onDestroy () { mUnityPlayer.quit(); super.onDestroy(); }
Result:

user1065434
source share