Intent.ACTION_MEDIA_SCANNER_SCAN_FILE:扫描指定文件

简介:

1.启动MediaScanner服务,扫描媒体文件:
程序通过发送下面的Intent启动MediaScanner服务扫描指定的文件或目录:

Intent.ACTION_MEDIA_SCANNER_SCAN_FILE:扫描指定文件

public void scanFileAsync(Context ctx, String filePath) {
              Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
              scanIntent.setData(Uri.fromFile(new File(filePath)));
              ctx.sendBroadcast(scanIntent);
       }

“android.intent.action.MEDIA_SCANNER_SCAN_DIR”:扫描指定目录

public static final String ACTION_MEDIA_SCANNER_SCAN_DIR = "android.intent.action.MEDIA_SCANNER_SCAN_DIR";
       public void scanDirAsync(Context ctx, String dir) {
              Intent scanIntent = new Intent(ACTION_MEDIA_SCANNER_SCAN_DIR);
              scanIntent.setData(Uri.fromFile(new File(dir)));
              ctx.sendBroadcast(scanIntent);
       }

这种扫描方式中,由于扫描工作是在MediaScanner服务中进行的,因此不会阻塞当前程序进程。当扫描大量媒体文件且实时性要求不高的情况下,适合使用该扫描方式。
相关文章
|
6月前
|
应用服务中间件 数据安全/隐私保护 容器
websphere Error 404:SRVE0190E: File not found: index.action
websphere Error 404:SRVE0190E: File not found: index.action
|
Android开发
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.C
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.C
Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.C
|
数据库管理 索引
Xamarin.Android 使用 SQLite 出现 Index -1 requested, with a size of 10 异常
异常: Android.Database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 10 此错误是数据返回到ICursor无法确定获取列的索引,那么需要加上一下代码即可。
1430 0
|
数据库管理
Xamarin.Android 使用 SQLite 出现 Couldn't read row 0, col -1 from CursorWindow. 异常
异常:Java.Lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it. 出现该问题一般分为两种情况: 1.请求的字段不在表中,可能是大小写没写对。
6455 0
|
Android开发 索引
Android 解析resources.arsc文件
1). 文件格式 resources.arsc文件格式.png 2). 头部信息 /** * Resource.arsc文件格式是由一系列的chunk构成,每一个chunk均包含ResChunk_header * * struct ...
1516 0
Didn't find class "android.support.v4.animation.AnimatorCompatHelper"
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.
1500 0