Added in API level 24

VrListenerService


abstract class VrListenerService : Service
kotlin.Any
   ↳ 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 android.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 android.app.Activity#setVrModeEnabled 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 android.app.Activity#setVrModeEnabled and if this service is installed and enabled in the current user's settings.

Summary

Constants
static String

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

Inherited constants
Public constructors

Public methods
static Boolean
isVrModePackageEnabled(context: Context, requestedComponent: ComponentName)

Checks if the given component is enabled in user settings.

open IBinder?
onBind(intent: Intent!)

open Unit

Called when the current activity using VR mode has changed.

Inherited functions

Constants

SERVICE_INTERFACE

Added in API level 24
static val SERVICE_INTERFACE: String

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

Value: "android.service.vr.VrListenerService"

Public constructors

VrListenerService

Added in API level 24
VrListenerService()

Public methods

isVrModePackageEnabled

Added in API level 24
static fun isVrModePackageEnabled(
    context: Context,
    requestedComponent: ComponentName
): Boolean

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 android.provider.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 android.service.vr.VrListenerService to check. This value cannot be null.
Return
Boolean true if this component is enabled in settings.

onBind

Added in API level 24
open fun onBind(intent: Intent!): IBinder?
Parameters
intent Intent!: The Intent that was used to bind to this service, as given to android.content.Context#bindService. Note that any extras that were included with the Intent at that point will not be seen here.
Return
IBinder? Return an IBinder through which clients can call on to the service.

onCurrentVrActivityChanged

Added in API level 24
open fun onCurrentVrActivityChanged(component: ComponentName!): Unit

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 android.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.