Black screen unity subview in android
Asked Answered
A

2

2

I try to using unity scene as a subview for my Android app. I did like this tutorial http://forum.unity3d.com/threads/using-unity-android-in-a-sub-view.98315/ . But I got a problem. My screen is black like this

enter image description here

And this is my java code MainActivity

package com.duy;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;

import com.unity3d.player.UnityPlayer;

public class MainActivity extends Activity {

    UnityPlayer m_UnityPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        m_UnityPlayer = new UnityPlayer(this);
        int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1);
        m_UnityPlayer.init(glesMode, false);

        FrameLayout layout = (FrameLayout) findViewById(R.id.unityView);
        LayoutParams lp = new LayoutParams(600, 800);
        layout.addView(m_UnityPlayer.getView(), 0, lp);

    }
    public void onWindowFocusChanged(boolean hasFocus)
    {
        super.onWindowFocusChanged(hasFocus);
        m_UnityPlayer.windowFocusChanged(hasFocus);
    }

}

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.duy"
android:versionCode="1"
android:versionName="1.0" >

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:windowSoftInputMode="adjustResize|adjustPan|stateHidden"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">

        <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
</application>
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="22" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />

and my layout activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/unityView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</FrameLayout>

Can you help me solve this problem. Thank you very much!

Argonaut answered 25/6, 2015 at 4:7 Comment(1)
do you manage to get it working? I encountered the exact same problem. :/Novation
K
0

Yor are specifying layout params in the code like this

LayoutParams lp = new LayoutParams(600, 800);

If you remove this line it might work properly.. :)

Kizzee answered 25/6, 2015 at 5:3 Comment(2)
Oh ok.. try giving fill_parent in layout params, instead of 600 and 800.. not sure if it will work..Kizzee
I think it is because of this line in ur manifest- android:windowSoftInputMode="adjustResize|adjustPan|stateHidden".. Check this link - developer.android.com/guide/topics/manifest/…..Kizzee
O
0

found the answer just add this line in your unity project's android library (unityLib) activity tag in your manifest file

android:process=":UnityKillsMe"

and also its mandatory to implement onWindowFocusChangedListener

onWindowFocusChanged(){m_UnityPlayer.windowFocusChanged(hasFocus);}

It will be solved https://gamedev.stackexchange.com/questions/134347/android-black-screen-with-unity-app-in-subview

Obsessive answered 21/2, 2017 at 8:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.