public abstract class MediaBrowserService extends Service
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 MediaSession
.
SERVICE_INTERFACE
action.
For example:
<service android:name=".MyMediaBrowserService" android:label="@string/service_name" > <intent-filter> <action android:name="android.media.browse.MediaBrowserService" /> </intent-filter> </service>
Modifier and Type | Class and Description |
---|---|
static class |
MediaBrowserService.BrowserRoot
Contains information that the browser service needs to send to the client
when first connected.
|
class |
MediaBrowserService.Result<T>
Completion handler for asynchronous callback methods in
MediaBrowserService . |
Service.StartArgFlags, Service.StartResult, Service.StopForegroundFlags
Context.BindServiceFlags, Context.CreatePackageOptions, Context.ServiceName
Modifier and Type | Field and Description |
---|---|
static String |
KEY_MEDIA_ITEM
A key for passing the MediaItem to the ResultReceiver in getItem.
|
static String |
SERVICE_INTERFACE
The
Intent that must be declared as handled by the service. |
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY, START_TASK_REMOVED_COMPLETE, STOP_FOREGROUND_DETACH, STOP_FOREGROUND_REMOVE
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BATTERY_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_ALLOW_WHITELIST_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_EXTERNAL_SERVICE, BIND_FOREGROUND_SERVICE, BIND_FOREGROUND_SERVICE_WHILE_AWAKE, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_SHOWING_UI, BIND_TREAT_LIKE_ACTIVITY, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAMERA_SERVICE, CAPTIONING_SERVICE, CARRIER_CONFIG_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_CREDENTIAL_PROTECTED_STORAGE, CONTEXT_DEVICE_PROTECTED_STORAGE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_REGISTER_PACKAGE, CONTEXT_RESTRICTED, CONTEXTHUB_SERVICE, COUNTRY_DETECTOR, DEVICE_IDLE_CONTROLLER, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, ETHERNET_SERVICE, FINGERPRINT_SERVICE, GATEKEEPER_SERVICE, HARDWARE_PROPERTIES_SERVICE, HDMI_CONTROL_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, JOB_SCHEDULER_SERVICE, KEYGUARD_SERVICE, LAUNCHER_APPS_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_PROJECTION_SERVICE, MEDIA_ROUTER_SERVICE, MEDIA_SESSION_SERVICE, MIDI_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_NO_LOCALIZED_COLLATORS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_SCORE_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, PERSISTENT_DATA_BLOCK_SERVICE, POWER_SERVICE, PRINT_SERVICE, RADIO_SERVICE, RECOVERY_SERVICE, RESTRICTIONS_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SHORTCUT_SERVICE, SIP_SERVICE, SOUND_TRIGGER_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, SYSTEM_HEALTH_SERVICE, TELECOM_SERVICE, TELEPHONY_SERVICE, TELEPHONY_SUBSCRIPTION_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, TRUST_SERVICE, TV_INPUT_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USAGE_STATS_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, VOICE_INTERACTION_MANAGER_SERVICE, WALLPAPER_SERVICE, WIFI_NAN_SERVICE, WIFI_P2P_SERVICE, WIFI_RTT_SERVICE, WIFI_SCANNING_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
MediaBrowserService() |
Modifier and Type | Method and Description |
---|---|
void |
dump(FileDescriptor fd,
PrintWriter writer,
String[] args)
Print the Service's state into the given stream.
|
Bundle |
getBrowserRootHints()
Gets the root hints sent from the currently connected
MediaBrowser . |
MediaSession.Token |
getSessionToken()
Gets the session token, or null if it has not yet been created
or if it has been destroyed.
|
void |
notifyChildrenChanged(String parentId)
Notifies all connected media browsers that the children of
the specified parent id have changed in some way.
|
void |
notifyChildrenChanged(String parentId,
Bundle options)
Notifies all connected media browsers that the children of
the specified parent id have changed in some way.
|
IBinder |
onBind(Intent intent)
Return the communication channel to the service.
|
void |
onCreate()
Called by the system when the service is first created.
|
abstract MediaBrowserService.BrowserRoot |
onGetRoot(String clientPackageName,
int clientUid,
Bundle rootHints)
Called to get the root information for browsing by a particular client.
|
abstract void |
onLoadChildren(String parentId,
MediaBrowserService.Result<List<MediaBrowser.MediaItem>> result)
Called to get information about the children of a media item.
|
void |
onLoadChildren(String parentId,
MediaBrowserService.Result<List<MediaBrowser.MediaItem>> result,
Bundle options)
Called to get information about the children of a media item.
|
void |
onLoadItem(String itemId,
MediaBrowserService.Result<MediaBrowser.MediaItem> result)
Called to get information about a specific media item.
|
void |
setSessionToken(MediaSession.Token token)
Call to set the media session.
|
attach, getApplication, onConfigurationChanged, onDestroy, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, onUnbind, setForeground, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
attachBaseContext, bindService, bindServiceAsUser, canStartActivityForResult, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermission, clearWallpaper, createApplicationContext, createConfigurationContext, createCredentialProtectedStorageContext, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getBasePackageName, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDatabasePath, getDataDir, getDir, getDisplay, getDisplayAdjustments, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFilesDir, getFileStreamPath, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPreferences, getSharedPreferencesPath, getSystemService, getSystemServiceName, getTheme, getThemeResId, getUserId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isCredentialProtectedStorage, isDeviceProtectedStorage, isRestricted, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastAsUser, sendBroadcastMultiplePermissions, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivitiesAsUser, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startActivityForResult, startInstrumentation, startIntentSender, startIntentSender, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver
bindServiceAsUser, createCredentialEncryptedStorageContext, createDeviceEncryptedStorageContext, getColor, getColorStateList, getDrawable, getSharedPrefsFile, getString, getString, getSystemService, getText, isCredentialEncryptedStorage, isDeviceEncryptedStorage, migrateDatabaseFrom, migrateSharedPreferencesFrom, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
public static final String SERVICE_INTERFACE
Intent
that must be declared as handled by the service.public static final String KEY_MEDIA_ITEM
public void onCreate()
Service
public IBinder onBind(Intent intent)
Service
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.
onBind
in class Service
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.public void dump(FileDescriptor fd, PrintWriter writer, String[] args)
Service
IBinder.dump(java.io.FileDescriptor, java.lang.String[])
method
on the IBinder
interface registered with ServiceManager.public abstract MediaBrowserService.BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints)
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.
clientPackageName
- The package name of the application which is
requesting access to browse media.clientUid
- The uid of the application which is requesting access to
browse media.rootHints
- 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.MediaBrowserService.BrowserRoot
for accessing this app's content or null.MediaBrowserService.BrowserRoot.EXTRA_RECENT
,
MediaBrowserService.BrowserRoot.EXTRA_OFFLINE
,
MediaBrowserService.BrowserRoot.EXTRA_SUGGESTED
public abstract void onLoadChildren(String parentId, MediaBrowserService.Result<List<MediaBrowser.MediaItem>> result)
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 MediaBrowserService.Result.sendResult(T)
with an empty list. When the given parentId
is invalid, implementations must
call result.sendResult
with null
, which will invoke
MediaBrowser.SubscriptionCallback#onError
.
parentId
- The id of the parent media item whose children are to be
queried.result
- The Result to send the list of children to.public void onLoadChildren(String parentId, MediaBrowserService.Result<List<MediaBrowser.MediaItem>> result, Bundle options)
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 MediaBrowserService.Result.sendResult(T)
with an empty list. When the given parentId
is invalid, implementations must
call result.sendResult
with null
, which will invoke
MediaBrowser.SubscriptionCallback#onError
.
parentId
- The id of the parent media item whose children are to be
queried.result
- The Result to send the list of children to.options
- 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.public void onLoadItem(String itemId, MediaBrowserService.Result<MediaBrowser.MediaItem> result)
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
, which will
invoke MediaBrowser.ItemCallback#onError
.
The default implementation calls result.sendResult
with null
.
itemId
- The id for the specific
MediaBrowser.MediaItem
.result
- The Result to send the item to.public void setSessionToken(MediaSession.Token token)
This should be called as soon as possible during the service's startup. It may only be called once.
token
- The token for the service's MediaSession
.public MediaSession.Token getSessionToken()
public final Bundle getBrowserRootHints()
MediaBrowser
.
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.IllegalStateException
- If this method is called outside of onLoadChildren(java.lang.String, android.service.media.MediaBrowserService.Result<java.util.List<android.media.browse.MediaBrowser.MediaItem>>)
or onLoadItem(java.lang.String, android.service.media.MediaBrowserService.Result<android.media.browse.MediaBrowser.MediaItem>)
MediaBrowserService.BrowserRoot.EXTRA_RECENT
,
MediaBrowserService.BrowserRoot.EXTRA_OFFLINE
,
MediaBrowserService.BrowserRoot.EXTRA_SUGGESTED
public void notifyChildrenChanged(String parentId)
parentId
- The id of the parent media item whose
children changed.public void notifyChildrenChanged(String parentId, Bundle options)
parentId
- The id of the parent media item whose
children changed.options
- A bundle of service-specific arguments to send
to the media browse. The contents of this bundle may
contain the information about the change.