November 6, 2019 update:
  • There's a new open source Cardboard SDK for iOS and Android NDK that offers a streamlined API, improved device compatibility, and built-in viewer profile QR code scanning. A corresponding Unity package (SDK) is planned for a future release. We recommend that all developers actively building for Google Cardboard migrate (iOS, Android NDK) to the new Cardboard SDK.
October 15, 2019 update:
  • The Daydream View VR headset is no longer available for purchase. However, you can continue to use the existing Google VR SDK to update and distribute your apps to the Google Play Store, and make them available to users in the Daydream app.

GvrActivity

public class GvrActivity

Base activity that provides easy integration with GVR headsets.

Exposes events to interact with GVR headsets and handles many of the details commonly required when creating an Activity for VR rendering.

This activity keeps the screen ON as long as it detects that the phone is moving. This way the screen saver won't kick in while users are experiencing VR content. If no phone movement is detected for ~30 seconds, the regular screen wakelock policy is restored.

Inherited Constants

Public Constructors

Public Methods

GvrView
getGvrView()
Returns the GvrView associated with this activity.
void
onBackPressed()
Invokes the currently configured "close" behavior, in addition to the default Activity.onBackPressed() behavior.
void
onCardboardTrigger()
Override to detect when the Cardboard trigger was pulled and released.
void
setGvrView(GvrView gvrView)
Associates a GVR view with this activity.
void
setGvrView(GvrView gvrView, boolean enableVrModeFallbacks)
Associates a GVR view with this activity.

Inherited Methods

Public Constructors

public GvrActivity ()

Public Methods

public GvrView getGvrView ()

Returns the GvrView associated with this activity.

Returns
  • The GvrView object associated with this activity. Can be null.

public void onBackPressed ()

Invokes the currently configured "close" behavior, in addition to the default Activity.onBackPressed() behavior.

For Cardboard apps, this will be identical to Activity.onBackPressed(). For Daydream apps, this will finish the Activity and restore the 2D launcher.

public void onCardboardTrigger ()

Override to detect when the Cardboard trigger was pulled and released.

Provides click-like events when the display is inside a Cardboard viewer.

public void setGvrView (GvrView gvrView)

Associates a GVR view with this activity.

This method does not set or change the content view, but associates the activity with a GvrView and ensures it receives any required activity lifecycle notifications.

This is automatically done if setContentView is used to directly set a GvrView object, and should be called if the GvrView is set in any other way (e.g. from a layout resource).

On Android N+, setting a valid GvrView will also enable VR mode while the activity is visible. If Google VR Services is not present or enabled, this will prompt the user to install or enable Google VR Services before continuing.

Parameters
gvrView The GvrView to associate with. Can be null.

public void setGvrView (GvrView gvrView, boolean enableVrModeFallbacks)

Associates a GVR view with this activity.

This method does not set or change the content view, but associates the activity with a GvrView and ensures it receives any required activity lifecycle notifications.

This is automatically done if setContentView is used to directly set a GvrView object, and should be called if the GvrView is set in any other way (e.g. from a layout resource).

On Android N+, setting a valid GvrView will also enable VR mode while the activity is visible. If Google VR Services is not present and enabled, this will prompt the user to install or enable Google VR Services before continuing if enableVrModeFallbacks has been set to true. If the user continues without Google VR Services present and enabled, the Android OS will not enter VR mode, and some functionality may not be available (e.g. the controller).

Parameters
gvrView The GvrView to associate with. Can be null.
enableVrModeFallbacks true to show the user a prompt to handle the case where Google VR Services is not present and enabled.