public class MediaScannerConnection
extends Object
implements ServiceConnection
java.lang.Object | |
↳ | android.media.MediaScannerConnection |
MediaScannerConnection为应用程序将新创建或下载的媒体文件传递给媒体扫描器服务提供了一种方法。 媒体扫描仪服务将从文件中读取元数据并将该文件添加到媒体内容提供商。 MediaScannerConnectionClient为媒体扫描器服务提供一个接口,以将新扫描文件的Uri返回给MediaScannerConnection类的客户端。
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) 构建 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
|
From interface android.content.ServiceConnection
|
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. |
boolean isConnected ()
返回我们是否连接到媒体扫描仪服务
Returns | |
---|---|
boolean |
true if we are connected, false otherwise |
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. |
void onServiceDisconnected (ComponentName className)
ServiceConnection接口的一部分。 不要打电话。
Parameters | |
---|---|
className |
ComponentName : The concrete component name of the service whose connection has been lost. |
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. |
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. |
也可以看看: