Added in API level 37

Builder


class Builder
kotlin.Any
   ↳ android.media.projection.MediaProjectionConfig.Builder

Summary

Public constructors

Public methods
MediaProjectionConfig

Builds a new immutable instance of MediaProjectionConfig

MediaProjectionConfig.Builder
setAudioRequested(isAudioRequested: Boolean)

This method informs the screen capture UI that the user should be presented with an option to also record audio along with the screen content.

MediaProjectionConfig.Builder
setInitiallySelectedSource(projectionSource: Int)

Indicates which projection source the UI component should display to the user first.

MediaProjectionConfig.Builder

Indicates to the system that the requesting application is offering its own content to be shared as PROJECTION_SOURCE_APP_CONTENT.

MediaProjectionConfig.Builder
setRequesterHint(requesterHint: String?)

Let the requesting app indicate who the requester of this MediaProjection session is.

MediaProjectionConfig.Builder
setSourceEnabled(source: Int, enabled: Boolean)

Set whether the UI component requesting the user permission to share their screen should display an option to share the specified source

Public constructors

Builder

Added in API level 37
Builder()

Public methods

build

Added in API level 37
fun build(): MediaProjectionConfig

Builds a new immutable instance of MediaProjectionConfig

Return
MediaProjectionConfig This value cannot be null.

setAudioRequested

Added in API level 37
fun setAudioRequested(isAudioRequested: Boolean): MediaProjectionConfig.Builder

This method informs the screen capture UI that the user should be presented with an option to also record audio along with the screen content. When isAudioRequested is set to true, the consent dialog will display a control, such as a toggle, allowing the user to enable or disable audio capture for the projection session. If set to false, this control will not be shown.

Parameters
isAudioRequested Boolean: true to request that the UI shows an audio capture option, false otherwise.
Return
MediaProjectionConfig.Builder this Builder instance for chaining.
This value cannot be null.

setInitiallySelectedSource

Added in API level 37
fun setInitiallySelectedSource(projectionSource: Int): MediaProjectionConfig.Builder

Indicates which projection source the UI component should display to the user first. Calling this method without enabling the respective choice will have no effect.

Parameters
projectionSource Int: Value is either 0 or a combination of the following:
Return
MediaProjectionConfig.Builder instance of this Builder.
This value cannot be null.

setOwnAppContentProvided

Added in API level 37
fun setOwnAppContentProvided(isEnabled: Boolean): MediaProjectionConfig.Builder

Indicates to the system that the requesting application is offering its own content to be shared as PROJECTION_SOURCE_APP_CONTENT.

When setOwnAppContentProvided is set to true, the requesting app's content will override any content from other apps that might have been displayed by the system.

If this application wishes to offer its own content to be shared, it must declare, in its manifest, a android.os.Service inheriting from AppContentProjectionService and declare an intent filter with an {@value AppContentProjectionService#SERVICE_INTERFACE} action. The service must be exported and protected by the android.Manifest.permission#MANAGE_MEDIA_PROJECTION permission

</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>
  

If supported by the device, the content will be displayed to the user in the media projection picker and AppContentProjectionService.onContentRequest(AppContentRequest) will be called, offering the a chance to this application to provide or update the content to be shared.

If the user selects an item from this list, AppContentProjectionService.onLoopbackProjectionStarted(AppContentProjectionSession,int) will be called and the projection session will be considered as started.

If the shared content becomes unavailable, this application will be responsible for calling AppContentProjectionSession.notifySessionStop(). If the session is stopped outside of this application AppContentProjectionService.onSessionStopped(AppContentProjectionSession) will be called.

Return
MediaProjectionConfig.Builder This value cannot be null.

setRequesterHint

Added in API level 37
fun setRequesterHint(requesterHint: String?): MediaProjectionConfig.Builder

Let the requesting app indicate who the requester of this MediaProjection session is.

The UI component prompting the user for the permission to start the session can use this hint to provide more information about the origin of the request (e.g. a browser tab title, a meeting id if sharing to a video conferencing app, a player name if sharing the screen within a game).

Note that setting this won't hide or change the name of the application requesting the session.

Parameters
requesterHint String?: the text representing the requester of this session.
This value may be null.
Return
MediaProjectionConfig.Builder instance of this Builder.
This value cannot be null.

setSourceEnabled

Added in API level 37
fun setSourceEnabled(
    source: Int,
    enabled: Boolean
): MediaProjectionConfig.Builder

Set whether the UI component requesting the user permission to share their screen should display an option to share the specified source

Parameters
source Int: the projection source to enable or disable.
Value is either 0 or a combination of the following:
enabled Boolean: true to enable the source, false otherwise
Return
MediaProjectionConfig.Builder this instance for chaining.
This value cannot be null.
Exceptions
java.lang.IllegalArgumentException if the source is not one of the valid sources.