0

I have found a few solutions to this problem, where the back or X button (in top-left corner) won't exit the application, but they no longer seem to work and my application keeps getting rejected from the Daydream Program.

I have found the following solutions:

And I have personally tried the following two variants:

    void LateUpdate() {
        GvrViewer.Instance.UpdateState();
        if (GvrViewer.Instance.BackButtonPressed || Input.GetKeyDown(KeyCode.Escape)) {
            Application.Quit();
        }
    }

And more simply:

    void Update() {
        if (Input.GetKeyDown(KeyCode.Escape)) {
            Application.Quit();
        }
    }

But with both variants, the application keeps getting rejected from the following reason:

The app does not exit when a user selects the home or back button When the user removes the phone from their viewer, both the close button (upper left corner) and the back button in the system bar should exit the VR app. The app must exit into 2D, not just Daydream Home. The close button must also be visible in your app.

I'm currently using Unity 5.6 and GoogleVR SDK 1.4.

Am I missing something? Is there any other way to detect that the back button/X button is pressed?

Colin Dumitru
  • 3,327
  • 6
  • 30
  • 47

2 Answers2

0

In case your app is launched from the Daydream app, calling Application.Quit() will only take you back to the daydream app, not the Android 2D app launcher.

What you need to do is to write the following code in Java

public void Quit(Activity currentActivity) {
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_LAUNCHER);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    currentActivity.startActivity(startMain);
}

And then invoke the above Java method from Unity.

Ji Fang
  • 3,288
  • 1
  • 21
  • 18
0
   void Update() {
        if (Input.GetKeyDown(KeyCode.Escape)) {
            Application.Quit();
        }
    }

This code will work with latest unity versions. Try with unity 2018 or higher

Codemaker2015
  • 12,190
  • 6
  • 97
  • 81