VrListenerService

public abstract class VrListenerService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.service.vr.VrListenerService


A service that is bound from the system while running in virtual reality (VR) mode.

To extend this class, you must declare the service in your manifest file with the Manifest.permission.BIND_VR_LISTENER_SERVICE permission and include an intent filter with the SERVICE_INTERFACE action. For example:

 <service android:name=".VrListener"
          android:label="@string/service_name"
          android:permission="android.permission.BIND_VR_LISTENER_SERVICE">
     <intent-filter>
         <action android:name="android.service.vr.VrListenerService" />
     </intent-filter>
 </service>
 

This service is bound when the system enters VR mode and is unbound when the system leaves VR mode.

The system will enter VR mode when an application that has previously called Activity.setVrModeEnabled(boolean, ComponentName) gains user focus. The system will only start this service if the VR application has specifically targeted this service by specifying its ComponentName in the call to Activity.setVrModeEnabled(boolean, ComponentName) and if this service is installed and enabled in the current user's settings.

Summary

Constants

String SERVICE_INTERFACE

The Intent that must be declared as handled by the service.

Inherited constants

Public constructors

VrListenerService()

Public methods

static final boolean isVrModePackageEnabled(Context context, ComponentName requestedComponent)

Checks if the given component is enabled in user settings.

IBinder onBind(Intent intent)

Return the communication channel to the service.

void onCurrentVrActivityChanged(ComponentName component)

Called when the current activity using VR mode has changed.

Inherited methods

Constants

SERVICE_INTERFACE

Added in API level 24
public static final String SERVICE_INTERFACE

The Intent that must be declared as handled by the service.

Constant Value: "android.service.vr.VrListenerService"

Public constructors

VrListenerService

Added in API level 24
public VrListenerService ()

Public methods

isVrModePackageEnabled

Added in API level 24
public static final boolean isVrModePackageEnabled (Context context, 
                ComponentName requestedComponent)

Checks if the given component is enabled in user settings.

If this component is not enabled in the user's settings, it will not be started when the system enters VR mode. The user interface for enabling VrListenerService components can be started by sending the Settings.ACTION_VR_LISTENER_SETTINGS intent.

Parameters
context Context: the Context to use for looking up the requested component. This value cannot be null.

requestedComponent ComponentName: the name of the component that implements VrListenerService to check. This value cannot be null.

Returns
boolean true if this component is enabled in settings.

onBind

Added in API level 24
public IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.

Returns
IBinder Return an IBinder through which clients can call on to the service.

onCurrentVrActivityChanged

Added in API level 24
public void onCurrentVrActivityChanged (ComponentName component)

Called when the current activity using VR mode has changed.

This will be called when this service is initially bound, but is not guaranteed to be called before onUnbind. In general, this is intended to be used to determine when user focus has transitioned between two VR activities. If both activities have declared R.attr.enableVrMode with this service (and this service is present and enabled), this service will not be unbound during the activity transition.

Parameters
component ComponentName: the ComponentName of the VR activity that the system has switched to, or null if the system is displaying a 2D activity in VR compatibility mode.