Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/media/MediaScannerConnection#nestedclasses) \| [Ctors](https://developer.android.com/reference/android/media/MediaScannerConnection#pubctors) \| [Methods](https://developer.android.com/reference/android/media/MediaScannerConnection#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/MediaScannerConnection#inhmethods)

# MediaScannerConnection

*** ** * ** ***

` public class MediaScannerConnection `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/content/ServiceConnection `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.MediaScannerConnection |

<br />

*** ** * ** ***

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` | `https://developer.android.com/reference/android/media/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` | `https://developer.android.com/reference/android/media/MediaScannerConnection.OnScanCompletedListener` Interface for notifying clients of the result of scanning a requested media file. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/media/MediaScannerConnection#MediaScannerConnection(android.content.Context,%20android.media.MediaScannerConnection.MediaScannerConnectionClient)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/media/MediaScannerConnection.MediaScannerConnectionClient client) ` Constructs a new MediaScannerConnection object. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/media/MediaScannerConnection#connect()() ` Initiates a connection to the media scanner service. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaScannerConnection#disconnect()() ` Releases the connection to the media scanner service. |
| ` boolean` | ` https://developer.android.com/reference/android/media/MediaScannerConnection#isConnected()() ` Returns whether we are connected to the media scanner service |
| ` void` | ` https://developer.android.com/reference/android/media/MediaScannerConnection#onServiceConnected(android.content.ComponentName,%20android.os.IBinder)(https://developer.android.com/reference/android/content/ComponentName className, https://developer.android.com/reference/android/os/IBinder service) ` Part of the ServiceConnection interface. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaScannerConnection#onServiceDisconnected(android.content.ComponentName)(https://developer.android.com/reference/android/content/ComponentName className) ` Part of the ServiceConnection interface. |
| ` void` | ` https://developer.android.com/reference/android/media/MediaScannerConnection#scanFile(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String path, https://developer.android.com/reference/java/lang/String mimeType) ` Requests the media scanner to scan a file. |
| ` static void` | ` https://developer.android.com/reference/android/media/MediaScannerConnection#scanFile(android.content.Context,%20java.lang.String[],%20java.lang.String[],%20android.media.MediaScannerConnection.OnScanCompletedListener)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/java/lang/String paths, https://developer.android.com/reference/java/lang/String mimeTypes, https://developer.android.com/reference/android/media/MediaScannerConnection.OnScanCompletedListener callback) ` Convenience for constructing a `https://developer.android.com/reference/android/media/MediaScannerConnection`, calling `https://developer.android.com/reference/android/media/MediaScannerConnection#connect()` on it, and calling `https://developer.android.com/reference/android/media/MediaScannerConnection#scanFile(java.lang.String,%20java.lang.String)` with the given <var translate="no">path</var> and <var translate="no">mimeType</var> when the connection is established. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/content/ServiceConnection ` ` default void` ` https://developer.android.com/reference/android/content/ServiceConnection#onBindingDied(android.content.ComponentName)(https://developer.android.com/reference/android/content/ComponentName name) `

Called when the binding to this connection is dead.
` default void` ` https://developer.android.com/reference/android/content/ServiceConnection#onNullBinding(android.content.ComponentName)(https://developer.android.com/reference/android/content/ComponentName name) `

Called when the service being bound has returned `null` from its `https://developer.android.com/reference/android/app/Service#onBind(android.content.Intent)` method.
` abstract void` ` https://developer.android.com/reference/android/content/ServiceConnection#onServiceConnected(android.content.ComponentName,%20android.os.IBinder)(https://developer.android.com/reference/android/content/ComponentName name, https://developer.android.com/reference/android/os/IBinder service) `

Called when a connection to the Service has been established, with the `https://developer.android.com/reference/android/os/IBinder` of the communication channel to the Service.
` abstract void` ` https://developer.android.com/reference/android/content/ServiceConnection#onServiceDisconnected(android.content.ComponentName)(https://developer.android.com/reference/android/content/ComponentName name) `

Called when a connection to the Service has been lost.

## Public constructors

### MediaScannerConnection

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public MediaScannerConnection (Context context, 
                MediaScannerConnection.MediaScannerConnectionClient client)
```

Constructs a new MediaScannerConnection object.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the Context object, required for establishing a connection to the media scanner service. <br /> |
| `client` | `MediaScannerConnection.MediaScannerConnectionClient`: an optional object implementing the MediaScannerConnectionClient interface, for receiving notifications from the media scanner. <br /> |

## Public methods

### connect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void connect ()
```

Initiates a connection to the media scanner service. `https://developer.android.com/reference/android/media/MediaScannerConnection.MediaScannerConnectionClient#onMediaScannerConnected()` will be called when the connection is established.

<br />

### disconnect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void disconnect ()
```

Releases the connection to the media scanner service.

<br />

### isConnected

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isConnected ()
```

Returns whether we are connected to the media scanner service

<br />

| Returns ||
|---|---|
| `boolean` | true if we are connected, false otherwise <br /> |

### onServiceConnected

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onServiceConnected (ComponentName className, 
                IBinder service)
```

Part of the ServiceConnection interface. Do not call.

<br />

| Parameters ||
|---|---|
| `className` | `ComponentName`: The concrete component name of the service that has been connected. <br /> |
| `service` | `IBinder`: The IBinder of the Service's communication channel, which you can now make calls on. <br /> |

### onServiceDisconnected

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onServiceDisconnected (ComponentName className)
```

Part of the ServiceConnection interface. Do not call.

<br />

| Parameters ||
|---|---|
| `className` | `ComponentName`: The concrete component name of the service whose connection has been lost. <br /> |

### scanFile

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 `https://developer.android.com/reference/android/media/MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String,%20android.net.Uri)` is called.

<br />

| Parameters ||
|---|---|
| `path` | `String`: the path to the file to be scanned. <br /> |
| `mimeType` | `String`: an optional mimeType for the file. If mimeType is null, then the mimeType will be inferred from the file extension. <br /> |

### scanFile

Added in [API level 8](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Convenience for constructing a `https://developer.android.com/reference/android/media/MediaScannerConnection`, calling `https://developer.android.com/reference/android/media/MediaScannerConnection#connect()` on it, and calling `https://developer.android.com/reference/android/media/MediaScannerConnection#scanFile(java.lang.String,%20java.lang.String)` with the given <var translate="no">path</var> and <var translate="no">mimeType</var> when the connection is established.

<br />

| 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 `https://developer.android.com/reference/android/media/MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String,%20android.net.Uri)` is called. <br /> |
| `paths` | `String`: Array of paths to be scanned. <br /> |
| `mimeTypes` | `String`: Optional array of MIME types for each path. If mimeType is null, then the mimeType will be inferred from the file extension. <br /> |
| `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. <br /> |

**See also:**

- `https://developer.android.com/reference/android/media/MediaScannerConnection#scanFile(java.lang.String,%20java.lang.String)`