MediaScannerConnection
open class MediaScannerConnection : ServiceConnection
kotlin.Any | |
↳ | android.media.MediaScannerConnection |
MediaScannerConnection provides a way for applications to pass a newly created or downloaded media file to the media scanner service. The media scanner service will read metadata from the file and add the file to the media content provider. The MediaScannerConnectionClient provides an interface for the media scanner service to return the Uri for a newly scanned file to the client of the MediaScannerConnection class.
Summary
Nested classes | |
---|---|
abstract |
An interface for notifying clients of MediaScannerConnection when a connection to the MediaScanner service has been established and when the scanning of a file has completed. |
abstract |
Interface for notifying clients of the result of scanning a requested media file. |
Public constructors | |
---|---|
MediaScannerConnection(context: Context!, client: MediaScannerConnection.MediaScannerConnectionClient!) Constructs a new MediaScannerConnection object. |
Public methods | |
---|---|
open Unit |
connect() Initiates a connection to the media scanner service. |
open Unit |
Releases the connection to the media scanner service. |
open Boolean |
Returns whether we are connected to the media scanner service |
open Unit |
onServiceConnected(className: ComponentName!, service: IBinder!) Part of the ServiceConnection interface. |
open Unit |
onServiceDisconnected(className: ComponentName!) Part of the ServiceConnection interface. |
open Unit |
Requests the media scanner to scan a file. |
open static Unit |
scanFile(context: Context!, paths: Array<String!>!, mimeTypes: Array<String!>!, callback: MediaScannerConnection.OnScanCompletedListener!) Convenience for constructing a |
Inherited functions | |
---|---|
Public constructors
MediaScannerConnection
MediaScannerConnection(
context: Context!,
client: MediaScannerConnection.MediaScannerConnectionClient!)
Constructs a new MediaScannerConnection object.
Parameters | |
---|---|
context |
Context!: the Context object, required for establishing a connection to the media scanner service. |
client |
MediaScannerConnection.MediaScannerConnectionClient!: an optional object implementing the MediaScannerConnectionClient interface, for receiving notifications from the media scanner. |
Public methods
connect
open fun connect(): Unit
Initiates a connection to the media scanner service. MediaScannerConnectionClient#onMediaScannerConnected()
will be called when the connection is established.
disconnect
open fun disconnect(): Unit
Releases the connection to the media scanner service.
isConnected
open fun isConnected(): Boolean
Returns whether we are connected to the media scanner service
Return | |
---|---|
Boolean |
true if we are connected, false otherwise |
onServiceConnected
open fun onServiceConnected(
className: ComponentName!,
service: IBinder!
): Unit
Part of the ServiceConnection interface. Do not call.
Parameters | |
---|---|
name |
The concrete component name of the service that has been connected. |
service |
IBinder!: The IBinder of the Service's communication channel, which you can now make calls on. |
onServiceDisconnected
open fun onServiceDisconnected(className: ComponentName!): Unit
Part of the ServiceConnection interface. Do not call.
Parameters | |
---|---|
name |
The concrete component name of the service whose connection has been lost. |
scanFile
open fun scanFile(
path: String!,
mimeType: String!
): Unit
Requests the media scanner to scan a file. Success or failure of the scanning operation cannot be determined until MediaScannerConnectionClient#onScanCompleted(String, Uri)
is called.
Parameters | |
---|---|
path |
String!: the path to the file to be scanned. |
mimeType |
String!: an optional mimeType for the file. If mimeType is null, then the mimeType will be inferred from the file extension. |
scanFile
open static fun scanFile(
context: Context!,
paths: Array<String!>!,
mimeTypes: Array<String!>!,
callback: MediaScannerConnection.OnScanCompletedListener!
): Unit
Convenience for constructing a MediaScannerConnection
, calling connect
on it, and calling scanFile(java.lang.String,java.lang.String)
with the given path and mimeType when the connection is established.
Parameters | |
---|---|
context |
Context!: The caller's Context, required for establishing a connection to the media scanner service. Success or failure of the scanning operation cannot be determined until MediaScannerConnectionClient#onScanCompleted(String, Uri) is called. |
paths |
Array<String!>!: Array of paths to be scanned. |
mimeTypes |
Array<String!>!: Optional array of MIME types for each path. If mimeType is null, then the mimeType will be inferred from the file extension. |
callback |
MediaScannerConnection.OnScanCompletedListener!: Optional callback through which you can receive the scanned URI and MIME type; If null, the file will be scanned but you will not get a result back. |
See Also