Share via


Activity.SetVrModeEnabled(Boolean, ComponentName) Method

Definition

Enable or disable virtual reality (VR) mode for this Activity.

[Android.Runtime.Register("setVrModeEnabled", "(ZLandroid/content/ComponentName;)V", "GetSetVrModeEnabled_ZLandroid_content_ComponentName_Handler", ApiSince=24)]
public virtual void SetVrModeEnabled (bool enabled, Android.Content.ComponentName requestedComponent);
[<Android.Runtime.Register("setVrModeEnabled", "(ZLandroid/content/ComponentName;)V", "GetSetVrModeEnabled_ZLandroid_content_ComponentName_Handler", ApiSince=24)>]
abstract member SetVrModeEnabled : bool * Android.Content.ComponentName -> unit
override this.SetVrModeEnabled : bool * Android.Content.ComponentName -> unit

Parameters

enabled
Boolean

true to enable this mode.

requestedComponent
ComponentName

the name of the component to use as a android.service.vr.VrListenerService while VR mode is enabled.

Attributes

Remarks

Enable or disable virtual reality (VR) mode for this Activity.

VR mode is a hint to Android system to switch to a mode optimized for VR applications while this Activity has user focus.

It is recommended that applications additionally declare android.R.attr#enableVrMode in their manifest to allow for smooth activity transitions when switching between VR activities.

If the requested android.service.vr.VrListenerService component is not available, VR mode will not be started. Developers can handle this case as follows:

String servicePackage = "com.whatever.app";
            String serviceClass = "com.whatever.app.MyVrListenerService";

            // Name of the component of the VrListenerService to start.
            ComponentName serviceComponent = new ComponentName(servicePackage, serviceClass);

            try {
               setVrModeEnabled(true, myComponentName);
            } catch (PackageManager.NameNotFoundException e) {
                   List&lt;ApplicationInfo> installed = getPackageManager().getInstalledApplications(0);
                   boolean isInstalled = false;
                   for (ApplicationInfo app : installed) {
                       if (app.packageName.equals(servicePackage)) {
                           isInstalled = true;
                           break;
                       }
                   }
                   if (isInstalled) {
                       // Package is installed, but not enabled in Settings.  Let user enable it.
                       startActivity(new Intent(Settings.ACTION_VR_LISTENER_SETTINGS));
                   } else {
                       // Package is not installed.  Send an intent to download this.
                       sentIntentToLaunchAppStore(servicePackage);
                   }
            }

Java documentation for android.app.Activity.setVrModeEnabled(boolean, android.content.ComponentName).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to