Most visited

Recently visited

Added in API level 1

MediaScannerConnection

public class MediaScannerConnection
extends Object implements ServiceConnection

java.lang.Object
   ↳ android.media.MediaScannerConnection


MediaScannerConnection为应用程序将新创建或下载的媒体文件传递给媒体扫描器服务提供了一种方法。 媒体扫描仪服务将从文件中读取元数据并将该文件添加到媒体内容提供商。 MediaScannerConnectionClient为媒体扫描器服务提供一个接口,以将新扫描文件的Uri返回给MediaScannerConnection类的客户端。

Summary

Nested classes

interface MediaScannerConnection.MediaScannerConnectionClient

用于在与MediaScanner服务建立连接并完成文件扫描时通知MediaScannerConnection客户端的界面。

interface MediaScannerConnection.OnScanCompletedListener

用于通知客户端扫描请求的媒体文件结果的界面。

Public constructors

MediaScannerConnection(Context context, MediaScannerConnection.MediaScannerConnectionClient client)

构造一个新的MediaScannerConnection对象。

Public methods

void connect()

启动与媒体扫描器服务的连接。

void disconnect()

释放与媒体扫描器服务的连接。

boolean isConnected()

返回我们是否连接到媒体扫描仪服务

void onServiceConnected(ComponentName className, IBinder service)

ServiceConnection接口的一部分。

void onServiceDisconnected(ComponentName className)

ServiceConnection接口的一部分。

void scanFile(String path, String mimeType)

请求媒体扫描器扫描文件。

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

构建 MediaScannerConnection便利 MediaScannerConnection ,调用 connect() ,并在建立连接时使用给定 路径mimeType调用 scanFile(Context, String[], String[], MediaScannerConnection.OnScanCompletedListener)

Inherited methods

From class java.lang.Object
From interface android.content.ServiceConnection

Public constructors

MediaScannerConnection

Added in API level 1
MediaScannerConnection (Context context, 
                MediaScannerConnection.MediaScannerConnectionClient client)

构造一个新的MediaScannerConnection对象。

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

Added in API level 1
void connect ()

启动与媒体扫描器服务的连接。 当连接建立时,将调用onMediaScannerConnected()

disconnect

Added in API level 1
void disconnect ()

释放与媒体扫描器服务的连接。

isConnected

Added in API level 1
boolean isConnected ()

返回我们是否连接到媒体扫描仪服务

Returns
boolean true if we are connected, false otherwise

onServiceConnected

Added in API level 1
void onServiceConnected (ComponentName className, 
                IBinder service)

ServiceConnection接口的一部分。 不要打电话。

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

Added in API level 1
void onServiceDisconnected (ComponentName className)

ServiceConnection接口的一部分。 不要打电话。

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

scanFile

Added in API level 1
void scanFile (String path, 
                String mimeType)

请求媒体扫描器扫描文件。 在调用onScanCompleted(String, Uri)之前无法确定扫描操作的成功或失败。

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

Added in API level 8
void scanFile (Context context, 
                String[] paths, 
                String[] mimeTypes, 
                MediaScannerConnection.OnScanCompletedListener callback)

方便构建 MediaScannerConnection ,呼吁 connect()它,并调用 scanFile(Context, String[], String[], MediaScannerConnection.OnScanCompletedListener)给定的 路径mime类型建立连接时。

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 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.

也可以看看:

Hooray!