AppContentProjectionService


public abstract class AppContentProjectionService
extends Service

java.lang.Object
   ↳ 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 AppContentProjectionService.SERVICE_INTERFACE
  2. set android:exported="true"
  3. be protected by 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 android.Manifest.permission.MANAGE_MEDIA_PROJECTION are allowed to call these callbacks.

Summary

Constants

String SERVICE_INTERFACE

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

Inherited constants

Public constructors

AppContentProjectionService()

Public methods

final IBinder onBind(Intent intent)

Return the communication channel to the service.

abstract void onContentRequest(AppContentRequest request)

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

abstract void onContentRequestCanceled()

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

abstract boolean onLoopbackProjectionStarted(AppContentProjectionSession session, int contentId)

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

abstract void onSessionStopped(AppContentProjectionSession session)

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

Inherited methods

Constants

SERVICE_INTERFACE

Added in API level 37
public static final String SERVICE_INTERFACE

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.

Constant Value: "android.media.projection.AppContentProjectionService"

Public constructors

AppContentProjectionService

public AppContentProjectionService ()

Public methods

onBind

Added in API level 37
public final 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.

onContentRequest

Added in API level 37
public abstract void onContentRequest (AppContentRequest request)

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
public abstract void onContentRequestCanceled ()

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
public abstract boolean onLoopbackProjectionStarted (AppContentProjectionSession session, 
                int contentId)

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

Returns
boolean true if the request has been fulfilled, false otherwise

onSessionStopped

Added in API level 37
public abstract void onSessionStopped (AppContentProjectionSession session)

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)