# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Nested Classes | Ctors | Methods | Inherited Methods

# MediaScannerConnection

`public class MediaScannerConnection`
`extends Object` `implements ServiceConnection`

java.lang.Object
↳ | 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
`interface` | `MediaScannerConnection.MediaScannerConnectionClient` 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.
`interface` | `MediaScannerConnection.OnScanCompletedListener` Interface for notifying clients of the result of scanning a requested media file.

### Public constructors
`MediaScannerConnection(Context context, MediaScannerConnection.MediaScannerConnectionClient client)` Constructs a new MediaScannerConnection object.

### Public methods
`void` | `connect()` Initiates a connection to the media scanner service.
`void` | `disconnect()` Releases the connection to the media scanner service.
`boolean` | `isConnected()` Returns whether we are connected to the media scanner service
`void` | `onServiceConnected(ComponentName className, IBinder service)` Part of the ServiceConnection interface.
`void` | `onServiceDisconnected(ComponentName className)` Part of the ServiceConnection interface.
`void` | `scanFile(String path, String mimeType)` Requests the media scanner to scan a file.
`static void` | `scanFile(Context context, String[] paths, String[] mimeTypes, MediaScannerConnection.OnScanCompletedListener callback)` 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.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.
From interface `android.content.ServiceConnection`
`default void` | `onBindingDied(ComponentName name)` Called when the binding to this connection is dead.
`default void` | `onNullBinding(ComponentName name)` Called when the service being bound has returned `null` from its `onBind()` method.
`abstract void` | `onServiceConnected(ComponentName name, IBinder service)` Called when a connection to the Service has been established, with the `IBinder` of the communication channel to the Service.
`abstract void` | `onServiceDisconnected(ComponentName name)` Called when a connection to the Service has been lost.

## Public constructors

### MediaScannerConnection

    public MediaScannerConnection (Context context,
                    MediaScannerConnection.MediaScannerConnectionClient client)

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

    public void connect ()

Initiates a connection to the media scanner service. `MediaScannerConnectionClient#onMediaScannerConnected()` will be called when the connection is established.

### disconnect

    public void disconnect ()

Releases the connection to the media scanner service.

### isConnected

    public boolean isConnected ()

Returns whether we are connected to the media scanner service

Returns
`boolean` | true if we are connected, false otherwise

### onServiceConnected

    public void onServiceConnected (ComponentName className,
                    IBinder service)

Part of the ServiceConnection interface. Do not call.

Parameters
`className` | `ComponentName`: 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

    public void onServiceDisconnected (ComponentName className)

Part of the ServiceConnection interface. Do not call.

Parameters
`className` | `ComponentName`: The concrete component name of the service whose connection has been lost.

### scanFile

    public void scanFile (String path,
                    String mimeType)

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

    public static void scanFile (Context context,
                    String[] paths,
                    String[] mimeTypes,
                    MediaScannerConnection.OnScanCompletedListener callback)

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` | `String`: Array of paths to be scanned.
`mimeTypes` | `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:

- `scanFile(String, String)`

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*