android4.4 ROM开发者全盘扫描解决方案
来源:互联网 发布:网络写字员兼职 编辑:程序博客网 时间:2024/05/20 07:32
大家都知道android4.4之后,google屏蔽了Intent.ACTION_MEDIA_MOUNTED,这个广播的放送。所以导致的问题是我们没法全盘扫描,最近百度了很多方案都只是给予MediaScannerConnection.scanFile(),这个解决方法,但是这个方法并不理想无法达到我们全盘扫描的目的。在找不到更好方案的前提下,我只能另辟蹊径了,作为一个android ROM开发者最大的优势是能改framework层及其他provider代码,所以以下解决方案是修改MediaProvider完成的。
直接上代码
AndroidManifest.xml
<receiver android:name="MediaScannerReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MEDIA_MOUNTED" /> <data android:scheme="file" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MEDIA_UNMOUNTED" /> <data android:scheme="file" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SCANNER_ALL" /> <data android:scheme="file" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MEDIA_SCANNER_SCAN_FILE" /> <data android:scheme="file" /> </intent-filter> </receiver>
MediaScannerReceiver.java
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); final Uri uri = intent.getData(); if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { // Scan both internal and external storage scan(context, MediaProvider.INTERNAL_VOLUME); scan(context, MediaProvider.EXTERNAL_VOLUME); } else { if (uri.getScheme().equals("file")) { // handle intents related to external storage String path = uri.getPath(); String externalStoragePath = Environment.getExternalStorageDirectory().getPath(); String legacyPath = Environment.getLegacyExternalStorageDirectory().getPath(); try { path = new File(path).getCanonicalPath(); } catch (IOException e) { Log.e(TAG, "couldn't canonicalize " + path); return; } if (path.startsWith(legacyPath)) { path = externalStoragePath + path.substring(legacyPath.length()); } Log.d(TAG, "action: " + action + " path: " + path); //在这就加一句话就是这么简单 if (Intent.ACTION_MEDIA_MOUNTED.equals(action) || action.equals("android.intent.action.SCANNER_ALL")) { // scan whenever any volume is mounted scan(context, MediaProvider.EXTERNAL_VOLUME); } else if (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE.equals(action) && path != null && path.startsWith(externalStoragePath + "/")) { scanFile(context, path); } } } }
然后只要在你想全盘扫描的时候发送android.intent.action.SCANNER_ALL广播就行了。
第三方应用单独来实现全盘扫描方法如果有哪位高手知道请评论告诉我。
0 0
- android4.4 ROM开发者全盘扫描解决方案
- index 与全盘扫描
- ExecutorService多线程扫描全盘路径
- oracle优化:避免全盘扫描
- 取消卡巴斯基的“全盘扫描”提示
- 分享一位大神的Symbian全盘扫描
- Symbian AO实现的全盘扫描
- unity3D 扫描全盘获取文件路径
- android4.4 wifi 扫描流程分析
- win32 汇编实现全盘文件扫描功能(杀毒程序的扫描全盘文件功能)
- Android4.0ROM深度客制化
- 教你提高杀毒效率永久告别病毒全盘扫描
- Android4.4(MT8685)源码WIFI--扫描和连接
- Android4.4拒绝发送扫描SD卡的广播
- android4.4 API 19 给开发者带来的新福利
- android4.4 魔趣 使用go备份的解决方案。
- Android4.4中WebView无法显示图片解决方案
- Android4.4设置windowSoftInputMode失效问题的解决方案
- android内存检测
- C run-time library
- [LeetCode][Java] Word Ladder
- 字符串匹配算法总结
- redis 快速入门实战
- android4.4 ROM开发者全盘扫描解决方案
- OpenCV矩阵运算
- HDU 1010 Tempter of the Bone
- VS2010静态编译安装Qt5.1.1+openssl
- phalcon:跟踪sql语句
- 数据结构——赫夫曼编码
- ctemplate模板
- VS2010+DCMTK3.6.0 : MT支持库 安装说明
- Rsync、Unison及DRBD的比较