MediaBrowserServiceCompat

abstract class MediaBrowserServiceCompat : Service


Base class for media browse services.

Media browse services enable applications to browse media content provided by an application and ask the application to start playing it. They may also be used to control content that is already playing by way of a MediaSessionCompat.

To extend this class, you must declare the service in your manifest file with an intent filter with the SERVICE_INTERFACE action. For example:
<service android:name=".MyMediaBrowserServiceCompat"
         android:label="@string/service_name" >
    <intent-filter>
        <action android:name="android.media.browse.MediaBrowserService" />
    </intent-filter>
</service>

Summary

Nested types

Contains information that the browser service needs to send to the client when first connected.

Completion handler for asynchronous callback methods in MediaBrowserServiceCompat.

Constants

const String!
SERVICE_INTERFACE = "android.media.browse.MediaBrowserService"

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

Public constructors

Public functions

Unit
dump(fd: FileDescriptor!, writer: PrintWriter!, args: Array<String!>!)
Bundle!

Gets the root hints sent from the currently connected MediaBrowserCompat.

MediaSessionManager.RemoteUserInfo

Gets the browser information who sent the current request.

MediaSessionCompat.Token?

Gets the session token, or null if it has not yet been created or if it has been destroyed.

Unit

Notifies all connected media browsers that the children of the specified parent id have changed in some way.

Unit
notifyChildrenChanged(parentId: String, options: Bundle)

Notifies all connected media browsers that the children of the specified parent id have changed in some way.

IBinder!
onBind(intent: Intent!)
Unit
Unit
onCustomAction(
    action: String,
    extras: Bundle!,
    result: MediaBrowserServiceCompat.Result<Bundle!>
)

Called to request a custom action to this service.

Unit
abstract MediaBrowserServiceCompat.BrowserRoot?
onGetRoot(clientPackageName: String, clientUid: Int, rootHints: Bundle?)

Called to get the root information for browsing by a particular client.

abstract Unit

Called to get information about the children of a media item.

Unit
onLoadChildren(
    parentId: String,
    result: MediaBrowserServiceCompat.Result<(Mutable)List<MediaBrowserCompat.MediaItem!>!>,
    options: Bundle
)

Called to get information about the children of a media item.

Unit

Called to get information about a specific media item.

Unit
onSearch(
    query: String,
    extras: Bundle!,
    result: MediaBrowserServiceCompat.Result<(Mutable)List<MediaBrowserCompat.MediaItem!>!>
)

Called to get the search result.

Unit

Call to set the media session.

Inherited Constants

From android.content.ComponentCallbacks2
From android.content.Context
const String!
ACCESSIBILITY_SERVICE = "accessibility"
const String!
ACCOUNT_SERVICE = "account"
const String!
ACTIVITY_SERVICE = "activity"
const String!
ALARM_SERVICE = "alarm"
const String!
APPWIDGET_SERVICE = "appwidget"
const String!
APP_OPS_SERVICE = "appops"
const String!
APP_SEARCH_SERVICE = "app_search"
const String!
AUDIO_SERVICE = "audio"
const String!
BATTERY_SERVICE = "batterymanager"
const Int
const Int
const Int
const Int
const Int
const Int
const Int
BIND_EXTERNAL_SERVICE = -2147483648
const Long
BIND_EXTERNAL_SERVICE_LONG = 4611686018427387904
const Int
const Int
const Int
const Int
const Int
const Int
const String!
BIOMETRIC_SERVICE = "biometric"
const String!
BLOB_STORE_SERVICE = "blob_store"
const String!
BLUETOOTH_SERVICE = "bluetooth"
const String!
BUGREPORT_SERVICE = "bugreport"
const String!
CAMERA_SERVICE = "camera"
const String!
CAPTIONING_SERVICE = "captioning"
const String!
CARRIER_CONFIG_SERVICE = "carrier_config"
const String!
CLIPBOARD_SERVICE = "clipboard"
const String!
COMPANION_DEVICE_SERVICE = "companiondevice"
const String!
CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics"
const String!
CONNECTIVITY_SERVICE = "connectivity"
const String!
CONSUMER_IR_SERVICE = "consumer_ir"
const Int
const Int
const Int
const String!
CREDENTIAL_SERVICE = "credential"
const String!
CROSS_PROFILE_APPS_SERVICE = "crossprofileapps"
const Int
const Int
const String!
DEVICE_LOCK_SERVICE = "device_lock"
const String!
DEVICE_POLICY_SERVICE = "device_policy"
const String!
DISPLAY_HASH_SERVICE = "display_hash"
const String!
DISPLAY_SERVICE = "display"
const String!
DOMAIN_VERIFICATION_SERVICE = "domain_verification"
const String!
DOWNLOAD_SERVICE = "download"
const String!
DROPBOX_SERVICE = "dropbox"
const String!
EUICC_SERVICE = "euicc"
const String!
FILE_INTEGRITY_SERVICE = "file_integrity"
const String!
FINGERPRINT_SERVICE = "fingerprint"
const String!
GAME_SERVICE = "game"
const String!
GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection"
const String!
HARDWARE_PROPERTIES_SERVICE = "hardware_properties"
const String!
HEALTHCONNECT_SERVICE = "healthconnect"
const String!
INPUT_METHOD_SERVICE = "input_method"
const String!
INPUT_SERVICE = "input"
const String!
IPSEC_SERVICE = "ipsec"
const String!
JOB_SCHEDULER_SERVICE = "jobscheduler"
const String!
KEYGUARD_SERVICE = "keyguard"
const String!
LAUNCHER_APPS_SERVICE = "launcherapps"
const String!
LAYOUT_INFLATER_SERVICE = "layout_inflater"
const String!
LOCALE_SERVICE = "locale"
const String!
LOCATION_SERVICE = "location"
const String!
MEDIA_COMMUNICATION_SERVICE = "media_communication"
const String!
MEDIA_METRICS_SERVICE = "media_metrics"
const String!
MEDIA_PROJECTION_SERVICE = "media_projection"
const String!
MEDIA_ROUTER_SERVICE = "media_router"
const String!
MEDIA_SESSION_SERVICE = "media_session"
const String!
MIDI_SERVICE = "midi"
const Int
MODE_APPEND = 32768
const Int
const Int

This property is deprecated.

const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const String!
const String!
NFC_SERVICE = "nfc"
const String!
NOTIFICATION_SERVICE = "notification"
const String!
NSD_SERVICE = "servicediscovery"
const String!
OVERLAY_SERVICE = "overlay"
const String!
PEOPLE_SERVICE = "people"
const String!
PERFORMANCE_HINT_SERVICE = "performance_hint"
const String!
POWER_SERVICE = "power"
const String!
PRINT_SERVICE = "print"
const Int
const Int
const Int
const String!
RESTRICTIONS_SERVICE = "restrictions"
const String!
ROLE_SERVICE = "role"
const String!
SEARCH_SERVICE = "search"
const String!
SENSOR_SERVICE = "sensor"
const String!
SHORTCUT_SERVICE = "shortcut"
const String!
STATUS_BAR_SERVICE = "statusbar"
const String!
STORAGE_SERVICE = "storage"
const String!
STORAGE_STATS_SERVICE = "storagestats"
const String!
SYSTEM_HEALTH_SERVICE = "systemhealth"
const String!
TELECOM_SERVICE = "telecom"
const String!
TELEPHONY_IMS_SERVICE = "telephony_ims"
const String!
const String!
TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service"
const String!
TEXT_CLASSIFICATION_SERVICE = "textclassification"
const String!
const String!
TV_INPUT_SERVICE = "tv_input"
const String!
TV_INTERACTIVE_APP_SERVICE = "tv_interactive_app"
const String!
UI_MODE_SERVICE = "uimode"
const String!
USAGE_STATS_SERVICE = "usagestats"
const String!
USB_SERVICE = "usb"
const String!
USER_SERVICE = "user"
const String!
VIBRATOR_MANAGER_SERVICE = "vibrator_manager"
const String!
VIBRATOR_SERVICE = "vibrator"

This property is deprecated.

const String!
VIRTUAL_DEVICE_SERVICE = "virtualdevice"
const String!
VPN_MANAGEMENT_SERVICE = "vpn_management"
const String!
WALLPAPER_SERVICE = "wallpaper"
const String!
WIFI_AWARE_SERVICE = "wifiaware"
const String!
WIFI_P2P_SERVICE = "wifip2p"
const String!
const String!
WIFI_SERVICE = "wifi"
const String!
WINDOW_SERVICE = "window"
From android.app.Service

Inherited functions

From android.content.Context
From android.content.ContextWrapper
Boolean
bindIsolatedService(
    service: Intent!,
    flags: Int,
    instanceName: String!,
    executor: Executor!,
    conn: ServiceConnection!
)
Boolean
bindService(service: Intent!, conn: ServiceConnection!, flags: Int)
Boolean
bindServiceAsUser(
    service: Intent!,
    conn: ServiceConnection!,
    flags: Int,
    user: UserHandle!
)
Int
Int
IntArray<Int>!
checkCallingOrSelfUriPermissions(
    uris: (Mutable)List<Uri!>!,
    modeFlags: Int
)
Int
Int
checkCallingUriPermission(uri: Uri!, modeFlags: Int)
IntArray<Int>!
checkCallingUriPermissions(uris: (Mutable)List<Uri!>!, modeFlags: Int)
Int
checkPermission(permission: String!, pid: Int, uid: Int)
Int
Int
checkUriPermission(uri: Uri!, pid: Int, uid: Int, modeFlags: Int)
IntArray<Int>!
checkUriPermissions(
    uris: (Mutable)List<Uri!>!,
    pid: Int,
    uid: Int,
    modeFlags: Int
)
Unit

This function is deprecated.

Context!
createAttributionContext(attributionTag: String!)
Context!
createConfigurationContext(overrideConfiguration: Configuration!)
Context!
createContext(contextParams: ContextParams!)
Context!
Context!
Context!
Context!
Context!
createPackageContext(packageName: String!, flags: Int)
Context!
createWindowContext(type: Int, options: Bundle!)
Array<String!>!
Boolean
Boolean
Boolean
Unit
enforceCallingOrSelfPermission(permission: String!, message: String!)
Unit
enforceCallingOrSelfUriPermission(
    uri: Uri!,
    modeFlags: Int,
    message: String!
)
Unit
enforceCallingPermission(permission: String!, message: String!)
Unit
enforceCallingUriPermission(uri: Uri!, modeFlags: Int, message: String!)
Unit
enforcePermission(permission: String!, pid: Int, uid: Int, message: String!)
Unit
enforceUriPermission(
    uri: Uri!,
    pid: Int,
    uid: Int,
    modeFlags: Int,
    message: String!
)
Array<String!>!
Context!
ApplicationInfo!
AssetManager!
AttributionSource!
String!
Context!
File!
ClassLoader!
File!
ContentResolver!
File!
File!
Int
File!
getDir(name: String!, mode: Int)
Display!
File!
Array<File!>!
File!
Array<File!>!
Array<File!>!

This function is deprecated.

File!
File!
Executor!
Looper!
File!
File!
Array<File!>!
String!
String!
PackageManager!
String!
String!
ContextParams!
Resources!
SharedPreferences!
getSharedPreferences(name: String!, mode: Int)
Any!
String!
getSystemServiceName(serviceClass: Class<Any!>!)
Resources.Theme!
Drawable!

This function is deprecated.

Int

This function is deprecated.

Int

This function is deprecated.

Unit
grantUriPermission(toPackage: String!, uri: Uri!, modeFlags: Int)
Boolean
Boolean
Boolean
Boolean
moveDatabaseFrom(sourceContext: Context!, name: String!)
Boolean
moveSharedPreferencesFrom(sourceContext: Context!, name: String!)
FileInputStream!
FileOutputStream!
openFileOutput(name: String!, mode: Int)
SQLiteDatabase!
openOrCreateDatabase(
    name: String!,
    mode: Int,
    factory: SQLiteDatabase.CursorFactory!
)
Drawable!

This function is deprecated.

Unit
Unit
Intent!
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit
revokeUriPermission(uri: Uri!, modeFlags: Int)
Unit
Unit
Unit
sendOrderedBroadcast(intent: Intent!, receiverPermission: String!)
Unit
sendOrderedBroadcastAsUser(
    intent: Intent!,
    user: UserHandle!,
    receiverPermission: String!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
sendStickyOrderedBroadcast(
    intent: Intent!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)

This function is deprecated.

Unit
sendStickyOrderedBroadcastAsUser(
    intent: Intent!,
    user: UserHandle!,
    resultReceiver: BroadcastReceiver!,
    scheduler: Handler!,
    initialCode: Int,
    initialData: String!,
    initialExtras: Bundle!
)

This function is deprecated.

Unit
setTheme(resid: Int)
Unit
setWallpaper(bitmap: Bitmap!)

This function is deprecated.

Unit
Unit
ComponentName!
Boolean
startInstrumentation(
    className: ComponentName!,
    profileFile: String!,
    arguments: Bundle!
)
Unit
startIntentSender(
    intent: IntentSender!,
    fillInIntent: Intent!,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int
)
ComponentName!
startService(service: Intent!)
Boolean
Unit
Unit
Unit
Unit
Unit
updateServiceGroup(conn: ServiceConnection!, group: Int, importance: Int)
From android.app.Service
Unit
Application!
Int
Unit
Unit
Unit
onRebind(intent: Intent!)
Unit
onStart(intent: Intent!, startId: Int)

This function is deprecated.

Int
onStartCommand(intent: Intent!, flags: Int, startId: Int)
Unit
onTaskRemoved(rootIntent: Intent!)
Unit
onTimeout(startId: Int)
Unit
onTrimMemory(level: Int)
Boolean
onUnbind(intent: Intent!)
Unit
startForeground(id: Int, notification: Notification!)
Unit
stopForeground(removeNotification: Boolean)

This function is deprecated.

Unit
Boolean
stopSelfResult(startId: Int)

Constants

SERVICE_INTERFACE

Added in 1.1.0
const val SERVICE_INTERFACE = "android.media.browse.MediaBrowserService": String!

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

Public constructors

MediaBrowserServiceCompat

Added in 1.1.0
MediaBrowserServiceCompat()

Public functions

dump

Added in 1.1.0
fun dump(fd: FileDescriptor!, writer: PrintWriter!, args: Array<String!>!): Unit

getBrowserRootHints

Added in 1.1.0
fun getBrowserRootHints(): Bundle!

Gets the root hints sent from the currently connected MediaBrowserCompat. The root hints are service-specific arguments included in an optional bundle sent to the media browser service when connecting and retrieving the root id for browsing, or null if none. The contents of this bundle may affect the information returned when browsing.

Note that this will return null when connected to android.media.browse.MediaBrowser and running on API 23 or lower.

Throws
java.lang.IllegalStateException

If this method is called outside of onLoadChildren, onLoadItem or onSearch.

getCurrentBrowserInfo

Added in 1.1.0
fun getCurrentBrowserInfo(): MediaSessionManager.RemoteUserInfo

Gets the browser information who sent the current request.

Throws
java.lang.IllegalStateException

If this method is called outside of onGetRoot or onLoadChildren or onLoadItem.

getSessionToken

Added in 1.1.0
fun getSessionToken(): MediaSessionCompat.Token?

Gets the session token, or null if it has not yet been created or if it has been destroyed.

notifyChildrenChanged

Added in 1.1.0
fun notifyChildrenChanged(parentId: String): Unit

Notifies all connected media browsers that the children of the specified parent id have changed in some way. This will cause browsers to fetch subscribed content again.

Parameters
parentId: String

The id of the parent media item whose children changed.

notifyChildrenChanged

Added in 1.1.0
fun notifyChildrenChanged(parentId: String, options: Bundle): Unit

Notifies all connected media browsers that the children of the specified parent id have changed in some way. This will cause browsers to fetch subscribed content again.

Parameters
parentId: String

The id of the parent media item whose children changed.

options: Bundle

A bundle of service-specific arguments to send to the media browse. The contents of this bundle may contain the information about the change.

onBind

Added in 1.1.0
fun onBind(intent: Intent!): IBinder!

onCreate

fun onCreate(): Unit

onCustomAction

Added in 1.1.0
fun onCustomAction(
    action: String,
    extras: Bundle!,
    result: MediaBrowserServiceCompat.Result<Bundle!>
): Unit

Called to request a custom action to this service.

Implementations must call either sendResult or sendError. If the requested custom action will be an expensive operation detach may be called before returning from this function, and then the service can send the result later when the custom action is completed. Implementation can also call sendProgressUpdate to send an interim update to the requester.

If the requested custom action is not supported by this service, call sendError. The default implementation will invoke sendError.

Parameters
action: String

The custom action sent from the media browser.

extras: Bundle!

The bundle of service-specific arguments sent from the media browser.

result: MediaBrowserServiceCompat.Result<Bundle!>

The Result to send the result of the requested custom action.

onDestroy

@CallSuper
@MainThread
fun onDestroy(): Unit

onGetRoot

Added in 1.1.0
abstract fun onGetRoot(clientPackageName: String, clientUid: Int, rootHints: Bundle?): MediaBrowserServiceCompat.BrowserRoot?

Called to get the root information for browsing by a particular client.

The implementation should verify that the client package has permission to access browse media information before returning the root id; it should return null if the client is not allowed to access this information.

Parameters
clientPackageName: String

The package name of the application which is requesting access to browse media.

clientUid: Int

The uid of the application which is requesting access to browse media.

rootHints: Bundle?

An optional bundle of service-specific arguments to send to the media browse service when connecting and retrieving the root id for browsing, or null if none. The contents of this bundle may affect the information returned when browsing.

Returns
MediaBrowserServiceCompat.BrowserRoot?

The BrowserRoot for accessing this app's content or null.

onLoadChildren

Added in 1.1.0
abstract fun onLoadChildren(
    parentId: String,
    result: MediaBrowserServiceCompat.Result<(Mutable)List<MediaBrowserCompat.MediaItem!>!>
): Unit

Called to get information about the children of a media item.

Implementations must call result.sendResult with the list of children. If loading the children will be an expensive operation that should be performed on another thread, result.detach may be called before returning from this function, and then result.sendResult called when the loading is complete.

In case the media item does not have any children, call sendResult with an empty list. When the given parentId is invalid, implementations must call result.sendResult with null, which will invoke onError.

Parameters
parentId: String

The id of the parent media item whose children are to be queried.

result: MediaBrowserServiceCompat.Result<(Mutable)List<MediaBrowserCompat.MediaItem!>!>

The Result to send the list of children to.

onLoadChildren

Added in 1.1.0
fun onLoadChildren(
    parentId: String,
    result: MediaBrowserServiceCompat.Result<(Mutable)List<MediaBrowserCompat.MediaItem!>!>,
    options: Bundle
): Unit

Called to get information about the children of a media item.

Implementations must call result.sendResult with the list of children. If loading the children will be an expensive operation that should be performed on another thread, result.detach may be called before returning from this function, and then result.sendResult called when the loading is complete.

In case the media item does not have any children, call sendResult with an empty list. When the given parentId is invalid, implementations must call result.sendResult with null, which will invoke onError.

Parameters
parentId: String

The id of the parent media item whose children are to be queried.

result: MediaBrowserServiceCompat.Result<(Mutable)List<MediaBrowserCompat.MediaItem!>!>

The Result to send the list of children to.

options: Bundle

A bundle of service-specific arguments sent from the media browse. The information returned through the result should be affected by the contents of this bundle.

onLoadItem

Added in 1.1.0
fun onLoadItem(
    itemId: String!,
    result: MediaBrowserServiceCompat.Result<MediaBrowserCompat.MediaItem!>
): Unit

Called to get information about a specific media item.

Implementations must call result.sendResult. If loading the item will be an expensive operation result.detach may be called before returning from this function, and then result.sendResult called when the item has been loaded.

When the given itemId is invalid, implementations must call result.sendResult with null.

The default implementation will invoke onError.

Parameters
itemId: String!

The id for the specific MediaBrowserCompat.MediaItem.

result: MediaBrowserServiceCompat.Result<MediaBrowserCompat.MediaItem!>

The Result to send the item to, or null if the id is invalid.

onSearch

Added in 1.1.0
fun onSearch(
    query: String,
    extras: Bundle!,
    result: MediaBrowserServiceCompat.Result<(Mutable)List<MediaBrowserCompat.MediaItem!>!>
): Unit

Called to get the search result.

Implementations must call result.sendResult. If the search will be an expensive operation result.detach may be called before returning from this function, and then result.sendResult called when the search has been completed.

In case there are no search results, call result.sendResult with an empty list. In case there are some errors happened, call result.sendResult with null, which will invoke onError.

The default implementation will invoke onError.

Parameters
query: String

The search query sent from the media browser. It contains keywords separated by space.

extras: Bundle!

The bundle of service-specific arguments sent from the media browser.

result: MediaBrowserServiceCompat.Result<(Mutable)List<MediaBrowserCompat.MediaItem!>!>

The Result to send the search result.

setSessionToken

Added in 1.1.0
fun setSessionToken(token: MediaSessionCompat.Token!): Unit

Call to set the media session.

This should be called as soon as possible during the service's startup. It may only be called once.

Parameters
token: MediaSessionCompat.Token!

The token for the service's MediaSessionCompat.