Added in API level 37

AppContentProjectionService


abstract class AppContentProjectionService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.media.projection.AppContentProjectionService

Service to be implemented by the application providing the MediaProjectionAppContent.

To receive media projection callbacks related to app content sharing, this service must:

  1. be declared with an intent-filter action {@value AppContentProjectionService#SERVICE_INTERFACE}
  2. set android:exported="true"
  3. be protected by {@value android.Manifest.permission#MANAGE_MEDIA_PROJECTION}
  4. set MediaProjectionConfig.Builder.setOwnAppContentProvided(boolean) to true

</application>
    ...
     <service
          android:exported="true"
          android:name="com.example.AppContentSharingService"
          android:permission="android.permission.MANAGE_MEDIA_PROJECTION">
        <intent-filter>
          <action android:name="android.media.projection.AppContentProjectionService"/>
        </intent-filter>
      </service>
    </application>
  

Only holders of {@value android.Manifest.permission#MANAGE_MEDIA_PROJECTION} are allowed to call these callbacks.

Summary

Constants
static String

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

Inherited constants
Public constructors

Public methods
IBinder
onBind(intent: Intent?)

Return the communication channel to the service.

abstract Unit

Called when the picker UI has been shown to the user.

abstract Unit

Called when the user didn't pick some app content to be shared.

abstract Boolean

Called when the user picked a content to be shared within the requesting app.

abstract Unit

Called when the sharing session has been ended by the user or the system.

Inherited functions

Constants

SERVICE_INTERFACE

Added in API level 37
static val SERVICE_INTERFACE: String

The Intent action that must be declared as handled by the service. Put this in your manifest to reply to requests for app content projection.

Value: "android.media.projection.AppContentProjectionService"

Public constructors

AppContentProjectionService

AppContentProjectionService()

Public methods

onBind

Added in API level 37
fun onBind(intent: Intent?): IBinder

Return the communication channel to the service. May return null if clients can not bind to the service. The returned android.os.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 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.

onContentRequest

Added in API level 37
abstract fun onContentRequest(request: AppContentRequest): Unit

Called when the picker UI has been shown to the user.

App content should be returned by calling AppContentRequest.provideContent(List)

If the user picks one of the offered app content, onLoopbackProjectionStarted(AppContentProjectionSession,int) will be called with the id corresponding to the chosen content. See MediaProjectionAppContent for more information about the id.

Parameters
request AppContentRequest: the request instance containing the characteristics of the content requested

onContentRequestCanceled

Added in API level 37
abstract fun onContentRequestCanceled(): Unit

Called when the user didn't pick some app content to be shared. This can happen if the projection request was canceled, or the user picked another source (e.g. display, whole app).

Any resources created for sharing app content, such as thumbnails, can be discarded at this point.

onLoopbackProjectionStarted

Added in API level 37
abstract fun onLoopbackProjectionStarted(
    session: AppContentProjectionSession,
    contentId: Int
): Boolean

Called when the user picked a content to be shared within the requesting app.

This can be called multiple times if the user picks a different content to be shared at a later point.

contentId is the id that has been provided by this application during the onContentRequest(AppContentRequest) call. See MediaProjectionAppContent for more information about the id.

Parameters
session AppContentProjectionSession: the session started for sharing the selected MediaProjectionAppContent
contentId Int: the id of the selected MediaProjectionAppContent
Return
Boolean true if the request has been fulfilled, false otherwise

onSessionStopped

Added in API level 37
abstract fun onSessionStopped(session: AppContentProjectionSession): Unit

Called when the sharing session has been ended by the user or the system. The shared resources can be discarded.

The provided session object is the same as the one provided when onLoopbackProjectionStarted(AppContentProjectionSession,int) was called. It can be used to identify the session that is being terminated.

Note that if the session is terminated by this service by calling AppContentProjectionSession.notifySessionStop(), this callback won't be called.

Parameters
session AppContentProjectionSession: the same session object that was passed in onLoopbackProjectionStarted(AppContentProjectionSession,int)