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

Quit to Daydream home screen?

Discussion in 'Daydream' started by mat9054, Feb 13, 2017.

  1. mat9054

    mat9054

    Joined:
    Nov 14, 2015
    Posts:
    42
    I'm looking for a way to quit to daydream home scree. Using Application.Quit() will go to device home screen, not really good when you have headset on.

    I saw daydreamApi.launchVrHomeScreen(); but not sure how I can call it when interacting with UI. Anyone can help me accessing this method?

    Thank you.
     
  2. mira_leung

    mira_leung

    Official Google Employee

    Joined:
    May 17, 2016
    Posts:
    70
    The expected behaviour is to return to the Android home screen for VR-only apps. For those that have both 2D and VR activities, the expectation is to return to the 2D activity.
     
  3. cvasquez-coiron

    cvasquez-coiron

    Joined:
    Nov 10, 2014
    Posts:
    22
    So, what would be the correct command to properly go back to Daydream Home Screen (stay in VR mode)? Application.Quit() closes the app and randomly goes to Daydream Home (VR) or 2D Android home screen....
     
  4. TimurB

    TimurB

    Joined:
    Oct 12, 2016
    Posts:
    21
    You are asking how to call java method from Unity. There are several ways. The most straightforward is to use AndroidJavaObject/AndroidJavaClass.
    Code (CSharp):
    1.     AndroidJavaObject daydreamApiObj;
    2.     void Start()
    3.     {
    4.         AndroidJavaClass player = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    5.         AndroidJavaObject androidActivity = player.GetStatic<AndroidJavaObject>("currentActivity");
    6.         AndroidJavaClass daydreamApiClass = new AndroidJavaClass("com.google.vr.ndk.base.DaydreamApi");
    7.         androidActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
    8.         daydreamApiObj = daydreamApiClass.CallStatic<AndroidJavaObject>("create", androidActivity)
    9.         ));
    10.     }
    11.     void openHomeScreen()
    12.     {
    13.         daydreamApiObj.Call("launchVrHomescreen");
    14.     }
     
  5. cvasquez-coiron

    cvasquez-coiron

    Joined:
    Nov 10, 2014
    Posts:
    22
    Worked perfectly accessing the java method! thanks.. it's a pity (and strange), that the Google VR SDK for Unity doesn't come with a direct call to launch the VR Home Screen... actually they are requesting this behavior for accepting Daydream apps but it looks like there is no other/direct way to call it by now.

    Thank you!