Search Unity

Is there a way to launch another Daydream app without leaving vr?

Discussion in 'Daydream' started by TimurB, Feb 1, 2017.

  1. TimurB

    TimurB

    Joined:
    Oct 12, 2016
    Posts:
    21
    In app quality requirement FN-S2 states suggest using
    daydreamApi.launchInVr(componentName)
    to launch another app in VR.

    Is there any way to do it in unity?
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  3. TimurB

    TimurB

    Joined:
    Oct 12, 2016
    Posts:
    21
    This seems like it should work. But it does not work.
    Code (CSharp):
    1. AndroidJavaClass daydreamApiClass = new AndroidJavaClass("com.google.vr.ndk.base.DaydreamApi");
    2. AndroidJavaObject daydreamApiObj = daydreamApiClass.CallStatic<AndroidJavaObject>("create");
    3. daydreamApiObj.Call("launchInVr", "https://www.youtube.com/watch?v=862r3XS2YB0");
     
  4. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  5. TimurB

    TimurB

    Joined:
    Oct 12, 2016
    Posts:
    21
     
  6. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Yep, the issue is that you are calling create with no parameters, which is not a valid method on the class. You are going to have to get the context instance like in the sample code and pass that into the create method call as a parameter.
     
  7. TimurB

    TimurB

    Joined:
    Oct 12, 2016
    Posts:
    21
    Is it strange that this code produces this error?
    Code (CSharp):
    1.     void Start () {
    2.         AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    3.         AndroidJavaObject context = jc.GetStatic<AndroidJavaObject>("currentActivity");
    4.         AndroidJavaClass daydreamApiClass = new AndroidJavaClass("com.google.vr.ndk.base.DaydreamApi");
    5.         AndroidJavaObject daydreamApiObj = daydreamApiClass.CallStatic<AndroidJavaObject>("create", context);
    6.         daydreamApiObj.Call("launchInVr", "https://www.youtube.com/watch?v=862r3XS2YB0");
    7.     }
     
  8. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
  9. TimurB

    TimurB

    Joined:
    Oct 12, 2016
    Posts:
    21
    Apparently it is quite simple.
    But there is a strange big red line in the middle of fade-in/fade-out transition. Is it normal?

    Code (CSharp):
    1.  
    2. AndroidJavaObject daydreamApiObj;
    3. void Start()
    4. {
    5.     AndroidJavaClass player = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    6.     AndroidJavaObject androidActivity = player.GetStatic<AndroidJavaObject>("currentActivity");
    7.     AndroidJavaClass daydreamApiClass = new AndroidJavaClass("com.google.vr.ndk.base.DaydreamApi");
    8.     androidActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
    9.     daydreamApiObj = daydreamApiClass.CallStatic<AndroidJavaObject>("create", androidActivity)
    10.     ));
    11. }
    12. public void openInYoutube(string videoUrl)
    13. {
    14.     AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
    15.     AndroidJavaObject uri = uriClass.CallStatic<AndroidJavaObject>("parse", videoUrl);
    16.     try
    17.     {
    18.         AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", "android.intent.action.VIEW");
    19.         intent.Call<AndroidJavaObject>("setPackage", "com.google.android.apps.youtube.vr");
    20.         intent.Call<AndroidJavaObject>("setData", uri);
    21.         daydreamApiObj.Call("launchInVr", intent);
    22.     }
    23.     catch (System.Exception e)
    24.     {
    25.         Debug.Log("Probably Youtube VR app not installed: " + e);
    26.     }
    27. }
    28.  
     
  10. mira_leung

    mira_leung

    Official Google Employee

    Joined:
    May 17, 2016
    Posts:
    70