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服务中进行的,因此不会阻塞当前程序进程。当扫描大量媒体文件且实时性要求不高的情况下,适合使用该扫描方式。
相关文章
|
5月前
|
应用服务中间件 数据安全/隐私保护 容器
websphere Error 404:SRVE0190E: File not found: index.action
websphere Error 404:SRVE0190E: File not found: index.action
|
存储 Android开发 索引
Android逆向:resource.arsc文件解析(Config List)
resource.arsc是APK打包过程中生成一个重要的文件,主要存储了整个应用哦中的资源索引。但是这个文件是一个二进制文件,并不可读,所以本文就通过解析它的二进制内容来读懂这个文件。
644 0
|
存储 Android开发 索引
resource.arsc解析之 Dynamic package reference
加载Theme出错 这是一篇补充文章,在做动态替换resId的过程中,我发现bag类型的ResTable_entry在使用过程中存在问题。比如style,其parent解析一直有问题
169 0
|
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无法确定获取列的索引,那么需要加上一下代码即可。
1423 0
|
Android开发 索引
Android 解析resources.arsc文件
1). 文件格式 resources.arsc文件格式.png 2). 头部信息 /** * Resource.arsc文件格式是由一系列的chunk构成,每一个chunk均包含ResChunk_header * * struct ...
1514 0
Didn't find class "android.support.v4.animation.AnimatorCompatHelper"
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.
1499 0