Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using Unity Android In a Sub View

Discussion in 'Android' started by markharkness, Jul 27, 2011.

  1. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I appreciate your posts here. I was able to complete my Jedi training and solved my issue.

    I took your example (modified it) and here's how you do the same thing, but without exporting to eclipse.

    You can override the AndroidManifest.xml, layouts, and icons by placing files into the Assets/Plugins/Android folder.

    Here's a complete project. The main point for me was to set the input focus to the container layout while putting the unity player in a child layout. And then I'm logging controller output. Check DDMS if you have a tablet with a bluetooth or usb controller.
     

    Attached Files:

  2. GQPHD

    GQPHD

    Joined:
    Nov 15, 2012
    Posts:
    8
    Thanks very very very very very very very very very very very very very very very much.
    Additionally, just copying asset libs, androidmanifest for UnityPlayerActivity, libmono and libunity to libs simply works, when you dont want to make andorid library project.
    And i wonder why you use UnityPlayerActivity, not just android activity. it just.. works. can you tell me why? key event?
    btw great thanks harris.

    And i wrote simple tutorial for it. have a look!

    How to use Unity in Subview - without android library project, and with ndk
     
    Last edited: Nov 15, 2012
  3. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Now that I have a full understanding of the system I just used an activity. The docs said that unity would pass back to generic motion events, but that didn't work unless I used an activity.

    I built-in some cool native unity stuff like auto generating the R.java from the layout file. I'll post some of the goodness in the coming months...
     
  4. GQPHD

    GQPHD

    Joined:
    Nov 15, 2012
    Posts:
    8
    realtime reply. haha.

    Events. yep that would be problem. I think i will do some more tests.
    and
    i think it cool. waiting for your work! have a good day. thanks.
     
  5. GQPHD

    GQPHD

    Joined:
    Nov 15, 2012
    Posts:
    8
    Im now using unity with ndk, but is there any way that i can call android's native c function from unity directly, using like dllimport or something?
    in short, not calling Unity>JavaJni>C native function, but calling Unity>C native function.
    enjoy dev. thanks.
     
  6. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Yes I've done it often enough I made a plugin generator. This should help you define the interface.
    http://u3d.as/3kL
    http://forum.unity3d.com/threads/150453-Standalone-Plugin-Maker

    I use that to define the C++ interface.

    And then I have an NDK compile script that I can integrate into my plugin generator. I'll add it to my todo list. I haven't had any feature requests yet on the standalone plugin maker. Feel free to post in that thread and ask about it.
     
  7. GQPHD

    GQPHD

    Joined:
    Nov 15, 2012
    Posts:
    8
    @tgraupmann YOU ARE VERY COOL. very cool works!. I will buy that soon.
    but that was not my expected answer. maybe my explanation was not enough, surely.

    what i'm now struggling is Using android's c++ native in UnitySubview cs. I am not going to use Plugins folder.
    The referenced library is at (AndroidProject)/libs/armeabi-v7a/libTest.so, not in plugins folder.

    My approach has been something like this, with no luck.
    [DllImport("/data/data/com.company.test/lib/libTest")]
    public static extern void exposedToUnityPlease();

    have you attempted such things? have any suggestion can you popup with?
     
  8. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Oh maybe our approaches are different. The NDK work that I've done, is to compile NDK as a native plugin and put that into the Assets/Plugins/Android folder. Maybe I need to do another example project. (wink)
     
  9. GQPHD

    GQPHD

    Joined:
    Nov 15, 2012
    Posts:
    8
    ohoh forget about it. solved!
    just adding plugins' *so files to android libs folder then using dllimport simply did the job.
    now unity is running in subview, and java ndk and unity shares instance! wow.(i make it too intricatedly. was bit simple though..)
    thnx anyw!
     
  10. sergiocaronte

    sergiocaronte

    Joined:
    Nov 12, 2012
    Posts:
    10
    How could I acessing PlayerPrefs inside the Activity? I tried PreferenceManager.getDefaultSharedPreferences.getString(), that is like NSUserDefault in iOS(and with that I can access PlayerPrefs in cocoa), but it didn't work.

    Any ideias?
     
  11. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    You just need to use an android plugin to pass your player pref settings back to your activity.
     
  12. sergiocaronte

    sergiocaronte

    Joined:
    Nov 12, 2012
    Posts:
    10
    Could u send me an example?
     
  13. sergiocaronte

    sergiocaronte

    Joined:
    Nov 12, 2012
    Posts:
    10
    I got an issue.

    I'm able to start my Main Activity(Pure Android), a screen full of buttons, where the user choose its mini game(aech mini game is a scene in Unity), when the user taps a button, I start another Activity that start Unity and choose the scene. It's working fine.

    But when I come back to Main Activity, and start another or the same game, I'd like to leave unity running in background( to avoid the splash screen every start game). To avoid this, I make the m_UnityPlayer static, but when I start the game Activity again, I got:

    Code (csharp):
    1. 12-01 12:28:05.357: E/GLSurfaceView(12159): eglCreateWindowSurface
    2. 12-01 12:28:05.357: E/GLSurfaceView(12159): java.lang.IllegalArgumentException: Make sure the SurfaceView or associated SurfaceHolder has a valid Surface
    3. 12-01 12:28:05.357: E/GLSurfaceView(12159):     at com.google.android.gles_jni.EGLImpl._eglCreateWindowSurface(Native Method)
    4. 12-01 12:28:05.357: E/GLSurfaceView(12159):     at com.google.android.gles_jni.EGLImpl.eglCreateWindowSurface(EGLImpl.java:90)
    5. 12-01 12:28:05.357: E/GLSurfaceView(12159):     at android.opengl.GLSurfaceView$DefaultWindowSurfaceFactory.createWindowSurface(GLSurfaceView.java:798)
    6. 12-01 12:28:05.357: E/GLSurfaceView(12159):     at android.opengl.GLSurfaceView$EglHelper.createSurface(GLSurfaceView.java:1065)
    7. 12-01 12:28:05.357: E/GLSurfaceView(12159):     at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1433)
    8. 12-01 12:28:05.357: E/GLSurfaceView(12159):     at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
    9. 12-01 12:36:05.087: I/DownloadManager(12438): in removeSpuriousFiles
    I think is because the new Activity is a new object.

    How can I update these SurfaceView or SurfaceHolder without to start UnityPlayer again? Is there a way to do what I want?
     
  14. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828

    Why not create a layout view with 5 unity web players on it? And then you switch between active UnityPlayers...
     
  15. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    It's on my todo list.
     
  16. sergiocaronte

    sergiocaronte

    Joined:
    Nov 12, 2012
    Posts:
    10
    I've already done. thanks
     
  17. sergiocaronte

    sergiocaronte

    Joined:
    Nov 12, 2012
    Posts:
    10
    I don't know, sounds like a filth approach.
     
  18. GQPHD

    GQPHD

    Joined:
    Nov 15, 2012
    Posts:
    8
    I think this thread, using unity in subview, should be expand much bigger. It needs more experiment, documentize, share ideas.
    How about making it main forum theme? isn't it will be good?
     
  19. LiefLayer

    LiefLayer

    Joined:
    Jan 6, 2013
    Posts:
    65
    I want to know too
     
  20. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I have two way communication going between C# and Java in the OUYA Unity Package.

    Sign up for [update notifications] as new OUYA Unity Package updates become available.
     
  21. zt2620zt

    zt2620zt

    Joined:
    Mar 13, 2013
    Posts:
    5
    hi,i did it as the same, here is the code.

    protected void onCreate (Bundle savedInstanceState)
    {
    mUnityPlayer = new UnityPlayer(this);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    getWindow().takeSurface(null);
    setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
    getWindow().setFormat(PixelFormat.RGB_565);

    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();


    LinearLayout l = new LinearLayout(this);
    EditText et = new EditText(this);
    et.setWidth(500);
    et.setHeight(60);
    l.addView(et);
    Button b = new Button(this);
    b.setWidth(150);
    b.setHeight(60);
    b.setText("SEND");
    l.addView(b);

    b.requestFocus();


    FrameLayout fl = new FrameLayout(this);

    LayoutParams lp = new LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

    fl.addView(playerView,0, lp);
    fl.addView(l);

    l.setFocusable(true);

    this.setContentView(fl);


    }

    /////
    but finally, the edittext and the button 'send' can't be interactived. only the unity view can be interactived. so do you know why? thx.
     
  22. TimcAim

    TimcAim

    Joined:
    Apr 2, 2013
    Posts:
    6
    Sounds like the same problem I had, I fixed it by editing a value in my AndroidManifest.xml file:
    Code (csharp):
    1. <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    to
    Code (csharp):
    1. <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    it was located in the following activity :
    Code (csharp):
    1.     <activity android:name="com.Company.ProductName.AndroidUnityTestNativeActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="sensor">
    2.       <meta-data android:name="android.app.lib_name" android:value="unity" />
    3.       <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    4.     </activity>
    Though I must admit, I don't really know what this setting does. I just started delving into android-unity merging. But now the unity view doesn't make the native android views unclickable
     
  23. ankuroctro

    ankuroctro

    Joined:
    Dec 5, 2013
    Posts:
    2
    thanks for providing the detailed tutorial. I have follow this tut but my final unity view is not appear on full screen rather it became too small i have used same code as u mentioned.
    FrameLayout layout = (FrameLayout) findViewById(R.id.frameLayout2);

    LayoutParams lp = new LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

    layout.addView(m_UnityPlayer.getView(), 0, lp);

    please reply back
     
  24. jvil

    jvil

    Joined:
    Jul 13, 2012
    Posts:
    263
    LayoutParams.FILL_PARENT is deprecated, use LayoutParams.MATCH_PARENT
     
  25. ankuroctro

    ankuroctro

    Joined:
    Dec 5, 2013
    Posts:
    2
    i have also tried LayoutParams.MATCH_PARENT but it did not change.
     
  26. alvintandian

    alvintandian

    Joined:
    Nov 20, 2013
    Posts:
    5
    Hi guys,

    I have followed the instruction by Rofl. For the first part (where we set our Activity as UnityPlayerActivity), it is working. However for the 2nd part (where we make the Unity as a subview of the whole Activity), it is displaying black screen.

    Here is the detailed info:-

    Unity Version: 4.3.1f1
    Eclipse Version: Kepler Service Release 1

    Steps:
    1. I created a simple Unity project where it involves a spinning cube, I name it 'SuperCube'.
    2. From Unity Editor, Build the project. Go to the Temp/StagingArea folder in the Unity project folder and copy it out and put it under a folder, I name it UnityLib.
    3. Open Eclipse, create a new 'Android Project From Existing Code', and direct the root folder to the UnityLib folder.
    4. Set the UnityLib as isLibrary in the project Properties/Android.
    5. Create a new 'Android Project' and followed the package name - in my case 'com.supercube.amazing', I name the project, SuperCube.
    6. Move the 'Assets/bin' folder from UnityLib to SuperCube's Assets folder.
    7. Instead of adding External JARs for my SuperCube, I copied the 'classes.jar' file from '...Unity\Editor\Data\PlaybackEngines\androidplayer\bin' folder to my Project Libs folder. So I open the project Properties/Java Build Path and then I choose 'Add JARs' and I choose the one in my Libs folder.
    8. I copied parts of the Android Manifest.xml from UnityLib to my SuperCube Manifest.xml (snippet below).
    9. I ensure that the targeted SDK for both my SuperCube and UnityLib are the same.

    Below is the code snippets.

    MainActivity.java
    Code (csharp):
    1.  
    2. package com.supercube.amazing;
    3.  
    4. import android.app.Activity;
    5. import android.os.Bundle;
    6. import android.view.ViewGroup.LayoutParams;
    7. import android.widget.FrameLayout;
    8.  
    9. import com.unity3d.player.UnityPlayer;
    10.  
    11. public class MainActivity extends Activity {
    12.  
    13.     UnityPlayer m_UnityPlayer;
    14.    
    15.     @Override
    16.     protected void onCreate(Bundle savedInstanceState) {
    17.         super.onCreate(savedInstanceState);
    18.         setContentView(R.layout.activity_main);
    19.        
    20.         m_UnityPlayer = new UnityPlayer(this);
    21.         int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1);
    22.         m_UnityPlayer.init(glesMode, false);
    23.                        
    24.         FrameLayout layout = (FrameLayout) findViewById(R.id.unityView);
    25.         LayoutParams lp = new LayoutParams(200, 300);
    26.         layout.addView(m_UnityPlayer.getView(), 0, lp);
    27.     }
    28.  
    29. }
    30.  
    activity_main.xml
    Code (csharp):
    1.  
    2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:id="@+id/unityView"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent" >
    6.  
    7. </FrameLayout>
    8.  
    SuperCube Manifest.xml
    Code (csharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.supercube.amazing"
    5.     android:installLocation="auto"
    6.     android:theme="@android:style/Theme.NoTitleBar"
    7.     android:versionCode="1"
    8.     android:versionName="1.0" >
    9.  
    10.     <supports-screens
    11.         android:anyDensity="true"
    12.         android:largeScreens="true"
    13.         android:normalScreens="true"
    14.         android:smallScreens="true"
    15.         android:xlargeScreens="true" />
    16.  
    17.     <application
    18.         android:debuggable="false"
    19.         android:icon="@drawable/app_icon"
    20.         android:label="@string/app_name" >
    21.                 <activity
    22.             android:name="com.supercube.amazing.MainActivity"
    23.             android:label="@string/app_name" >
    24.             <intent-filter>
    25.                 <action android:name="android.intent.action.MAIN" />
    26.  
    27.                 <category android:name="android.intent.category.LAUNCHER" />
    28.             </intent-filter>
    29.         </activity>
    30.         <activity
    31.             android:name="com.unity3d.player.UnityPlayerNativeActivity"
    32.             android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
    33.             android:label="@string/app_name"
    34.             android:launchMode="singleTask"
    35.             android:screenOrientation="portrait" >
    36.             <meta-data
    37.                 android:name="unityplayer.ForwardNativeEventsToDalvik"
    38.                 android:value="false" />
    39.         </activity>
    40.     </application>
    41.  
    42.     <uses-sdk
    43.         android:minSdkVersion="14"
    44.         android:targetSdkVersion="19" />
    45.  
    46.     <uses-feature android:glEsVersion="0x00020000" />
    47.     <uses-feature android:name="android.hardware.sensor.accelerometer" />
    48.     <uses-feature android:name="android.hardware.touchscreen" />
    49.     <uses-feature
    50.         android:name="android.hardware.touchscreen.multitouch"
    51.         android:required="false" />
    52.     <uses-feature
    53.         android:name="android.hardware.touchscreen.multitouch.distinct"
    54.         android:required="false" />
    55.  
    56. </manifest>
    57.  
    UnityLib Manifest.xml
    Code (csharp):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.supercube.amazing" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
    4.   <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
    5.   <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    6.     <activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
    7.       <intent-filter>
    8.         <action android:name="android.intent.action.MAIN" />
    9.         <category android:name="android.intent.category.LAUNCHER" />
    10.       </intent-filter>
    11.       <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    12.     </activity>
    13.   </application>
    14.   <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />
    15.   <uses-feature android:glEsVersion="0x00020000" />
    16.   <uses-feature android:name="android.hardware.sensor.accelerometer" />
    17.   <uses-feature android:name="android.hardware.touchscreen" />
    18.   <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
    19.   <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
    20. </manifest>
    21.  
    Is there anything that I'm missing or do I have any wrong implementation?
    Help is much appreciated :)
     
    roboticvn likes this.
  27. alvintandian

    alvintandian

    Joined:
    Nov 20, 2013
    Posts:
    5
    I manage to fix it.
    By adding this piece of code in MainActivity.java:
    Code (csharp):
    1.  
    2.     public void onWindowFocusChanged(boolean hasFocus)
    3.     {
    4.         super.onWindowFocusChanged(hasFocus);
    5.         m_UnityPlayer.windowFocusChanged(hasFocus);
    6.     }
    7.  
     
  28. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    Hi, I created a VideoView inside of my FrameLayout, how can I play a video on top of Unity view?
     
  29. csjzz

    csjzz

    Joined:
    Mar 4, 2014
    Posts:
    1
    hi tnetennba . Your codes work.But I have another problem that : I wanna Use several unity-lib in one anroid-project.
     
  30. grennis

    grennis

    Joined:
    Mar 8, 2014
    Posts:
    3
    Hey guys

    Just wanted to thank the OP and folks in this thread who contributed. I got unity working in a subview - actually a fragment inside a view which has it's own view. Things have changed since the last posts, so here are some changes I had to make:

    - As one person mentioned but I want to emphasize: There is no need to create a library project. This just complicates things. Just copy the libs and assets over, make sure you got the right native libs, and update your manifest with the uses-feature and uses-permissions you can copy from the unity app.
    - One person mentioned you have to call windowFocusChanged(...). I found this as well, and I also found you have to call resume(...). In fact I think resume(...) and pause(...) on the Unity player are supposed to be called from lifecycle events onPause(..) and onResume(...)
    - This was also critical: You dont call getView() on the unity player anymore. You just pass the player itself because it derives from View. So, this is how you do it now: container.addView(mUnityPlayer, 0, lp)

    I am using this now not with Eclipse, but with Android Studio and Gradle. It was painful to get the native libraries bundled but I eventually got it to work by zipping them up and including them as a JAR.

    I also got the unity player with vuphoria AR working inside a sub-view (fragment), and this was actually much more challenging. I posted my solution here: https://developer.vuforia.com/forum/android/qcarunityplayer-subview

    Hope this helps.
     
    Last edited: Mar 8, 2014
  31. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    Hi,
    I managed to play Unity in a standard Android fullscreen view, what I want to do now is to change to another view and then switch back to my main view (the unity one).
    How can I achieve that?
    I already searched on the internet but with no luck.
     
  32. grennis

    grennis

    Joined:
    Mar 8, 2014
    Posts:
    3
    Just wanted to confirm that resume() and pause() are meant to be called from activity lifecycle events. You can check the source code for the UnityPlayerActivity to see this, in Install directory\Editor\Data\PlaybackEngines\androidplayer\src\com\unity3d\player
     
  33. grennis

    grennis

    Joined:
    Mar 8, 2014
    Posts:
    3
    You can simply call setVisibility(...) on the views you want to hide and show. That's why this technique is so valuable, you can treat the unity view and just any standard android view.
     
  34. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    Could you paste an example xml because I tried to do that days ago but we no luck.
     
  35. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    Hi,
    What to do if I want to combine two unity android project in one (third) eclipse android project?
    Any suggestion how to combine data from bin folder?
    rahu
     
  36. dhanrajsinh24

    dhanrajsinh24

    Joined:
    May 8, 2014
    Posts:
    59
    I am having this error in logcat of eclipse. I followed all the steps. what could be the problem?
    01-16 21:44:26.829: E/AndroidRuntime(27916): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.test.testcustomlayout/com.unity3d.player.UnityPlayerNativeActivity}: java.lang.ClassNotFoundException: Didn't find class "com.unity3d.player.UnityPlayerNativeActivity" on path: DexPathList[dexElements=[zip file "/mnt/asec/com.test.testcustomlayout-2/pkg.apk"],nativeLibraryDirectories=[/mnt/asec/com.test.testcustomlayout-2/lib, /vendor/lib, /system/lib]]
     
  37. lclandld

    lclandld

    Joined:
    Feb 2, 2015
    Posts:
    2
    I have an activity extends FragmentActivity, in fragments new UnityPlayer (activity); by this way,why my screen is black?
     
  38. lclandld

    lclandld

    Joined:
    Feb 2, 2015
    Posts:
    2
    hi,Do you solved this show problem of black screen?
     
  39. PrisedRabbit

    PrisedRabbit

    Joined:
    Aug 14, 2012
    Posts:
    62
  40. Esildorr

    Esildorr

    Joined:
    Mar 25, 2014
    Posts:
    1
    Hi all!

    Were trying to get Unity to open on top of our pre-existing Android app. We want this to act as an Android View, so we can pause, resume, and possibly resume it as we please. We have already taken most of the steps the steps to get it there but it we are having this issue:



    This is a sample app we set up to test this functionality. Back in the pre-existing Android app, when the user starts it, it creates the view…..We get this, the blue you see in the background is an android view that is colored this eventually will be transparent. The black, is the problem. This is where Unity should be displaying. Here is a snippet of the Java code we are using to create and start the view:

    Code (CSharp):
    1. public void resumeIQ360(final JSONObject jsonData){
    2.  
    3.         final CordovaWebView localAppView = appMobile.appView;
    4.         final Display display = appMobile.getWindowManager().getDefaultDisplay();
    5.         final DisplayMetrics metrics = new DisplayMetrics();
    6.         display.getRealMetrics(metrics);
    7.         /*
    8.         super.setBooleanProperty("setFullscreen", true);
    9.         super.setIntegerProperty("loadUrlTimeoutValue", 600000000);
    10.         requestWindowFeature(Window.FEATURE_NO_TITLE);
    11.         */
    12.         iq360WasStartedByUser = true;
    13.  
    14.         FrameLayout.LayoutParams smartappLayoutParams = new FrameLayout.LayoutParams(0, 0);
    15.         localAppView.setLayoutParams(smartappLayoutParams);
    16.  
    17.         if(mUnityPlayer == null){
    18.             load360View(metrics);
    19.         }
    20.  
    21.        // mUnityPlayer.resume();
    22.  
    23.         FrameLayout.LayoutParams apLayoutParams = new FrameLayout.LayoutParams(200, 200);
    24.         View playerView = mUnityPlayer.getView();
    25.         playerView.setLayoutParams(apLayoutParams);
    26.         playerView.setBackgroundColor(Color.RED);
    27.         playerView.requestFocus();
    28.         mUnityPlayer.setBackgroundColor(Color.GREEN);
    29.         mUnityPlayer.setVisibility(View.VISIBLE);
    30.         mUnityPlayer.forceLayout();
    31.         mUnityPlayer.recomputeViewAttributes(playerView);
    32.         mUnityPlayer.resume();
    33.  
    34.         String finalizedData = "[" + jsonData.toString() + "]";
    35.         mUnityPlayer.UnitySendMessage("Game Manager", "SetInitData", finalizedData);
    36.  
    37.     }
    38.  
    39. public void load360View(DisplayMetrics metrics){
    40.  
    41.         getWindow().takeSurface(null);
    42.         setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
    43.         getWindow().setFormat(PixelFormat.RGB_565);
    44.         mUnityPlayer = new UnityPlayer(appMobile);
    45.         if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
    46.             getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
    47.                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
    48.  
    49.         int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
    50.         boolean trueColor8888 = false;
    51.         mUnityPlayer.init(glesMode, trueColor8888);
    52.  
    53.         setContentView(R.layout.main);
    54.         FrameLayout layout = (FrameLayout) findViewById(R.id.unityFrame);
    55.         FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(200 , 200);
    56.         View playerView = mUnityPlayer.getView();
    57.         layout.addView(playerView, 0, lp);
    58.         mUnityPlayer.recomputeViewAttributes(playerView);
    59.         mUnityPlayer.forceLayout();
    60.     }
    Any reason why its doing this? We’ve tried multiple phones, tablets, and manufacturers. Any help would be appreciated.
     
  41. yaotouge

    yaotouge

    Joined:
    Jun 15, 2015
    Posts:
    3
    hello,I managed to add unityplayer in a android framelayout subview, but how to close the unityplayer without exit current activity, when I call unityplayer.quit(), everything is terminated, could you give me some help?
     
  42. anirudha_vfx

    anirudha_vfx

    Joined:
    Oct 12, 2013
    Posts:
    11
  43. anirudha_vfx

    anirudha_vfx

    Joined:
    Oct 12, 2013
    Posts:
    11
    I'm having problem with the double app installation is showing in the app list.
    There are 2 installation, one for the Android app and another of the Unity.
    How can we use a single app icon in the app drawer?
    I have integrated Unity3d in the App and its running fine.
     
  44. yaotouge

    yaotouge

    Joined:
    Jun 15, 2015
    Posts:
    3
    Thanks, but I have already read that question before, my situation is a little different from that, the unityplayer is just a part of my activity, there are many other things in current activity, so when quit unityplayer, I don't wanna it destroy the whole activity :)
     
  45. roboticvn

    roboticvn

    Joined:
    Jun 24, 2015
    Posts:
    5
    Hi all!
    I got a prolblem where we make the Unity as a subview of the whole Activity. My screen is black like this

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

    PrisedRabbit

    Joined:
    Aug 14, 2012
    Posts:
    62
  47. maxv

    maxv

    Joined:
    Oct 2, 2015
    Posts:
    1
    everything working. it was my error. thx for tutorial
     
    Last edited: Oct 2, 2015
  48. Arsinx

    Arsinx

    Joined:
    Apr 14, 2014
    Posts:
    55
    Is there a way to make to have more then one game as subview, with one game open at a time.
    For example an App in which user selects which game to play and then can navigate back to the main app which has other screens and then decide to play other games from within the App as well.
     
    rahuxx likes this.
  49. spav

    spav

    Joined:
    May 31, 2013
    Posts:
    4
    bumping last question ^
     
  50. ipadress

    ipadress

    Joined:
    Feb 16, 2016
    Posts:
    1
    Are there any tutorials on doing the same thing with Android Studio?