Chinaunix首页 | 论坛 | 博客
  • 博客访问: 270746
  • 博文数量: 95
  • 博客积分: 2047
  • 博客等级: 大尉
  • 技术积分: 1022
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-14 16:18
文章分类

全部博文(95)

文章存档

2013年(1)

2011年(94)

我的朋友

分类: 嵌入式

2011-09-08 13:46:05




src/com/android/providers/media/MediaScannerReceiver.java View file @ aa20f4d
... ...
@@ -35,29 +35,27 @@ public class MediaScannerReceiver extends BroadcastReceiver
35 35
     public void onReceive(Context context, Intent intent) {
36 36
         String action = intent.getAction();
37 37
         Uri uri = intent.getData();
38
-        String externalStoragePath = Environment.getExternalStorageDirectory().getPath();
39 38
 
40 39
         if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
41 40
             // scan internal storage
42
-            scan(context, MediaProvider.INTERNAL_VOLUME);
  41
+            scan(context, MediaProvider.INTERNAL_VOLUME, null);
43 42
         } else {
44 43
             if (uri.getScheme().equals("file")) {
45 44
                 // handle intents related to external storage
46 45
                 String path = uri.getPath();
47
-                if (action.equals(Intent.ACTION_MEDIA_MOUNTED) && 
48
-                        externalStoragePath.equals(path)) {
49
-                    scan(context, MediaProvider.EXTERNAL_VOLUME);
50
-                } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE) &&
51
-                        path != null && path.startsWith(externalStoragePath + "/")) {
  46
+                if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
  47
+                    scan(context, MediaProvider.EXTERNAL_VOLUME, path);
  48
+                } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)) {
52 49
                     scanFile(context, path);
53 50
                 }
54 51
             }
55 52
         }
56 53
     }
57 54
 
58
-    private void scan(Context context, String volume) {
  55
+    private void scan(Context context, String volume, String path) {
59 56
         Bundle args = new Bundle();
60 57
         args.putString("volume", volume);
  58
+        args.putString("path", path);
61 59
         context.startService(
62 60
                 new Intent(context, MediaScannerService.class).putExtras(args));
63 61
     }    
src/com/android/providers/media/MediaScannerService.java View file @ aa20f4d
... ...
@@ -256,9 +256,13 @@ public class MediaScannerService extends Service implements Runnable
256 256
                         };
257 257
                     }
258 258
                     else if (MediaProvider.EXTERNAL_VOLUME.equals(volume)) {
  259
+                        String path = arguments.getString("path");
  260
+                        if (path == null) {
  261
+                            path = Environment.getExternalStorageDirectory().getPath();
  262
+                        }
259 263
                         // scan external storage
260 264
                         directories = new String[] {
261
-                                Environment.getExternalStorageDirectory().getPath(),
  265
+                                path,
262 266
                                 };
263 267
                     }
阅读(1556) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~