FileDocCategorySizeDatePackage
MediaScannerReceiver.javaAPI DocAndroid 1.5 API2978Wed May 06 22:42:48 BST 2009com.android.providers.media

MediaScannerReceiver

public class MediaScannerReceiver extends android.content.BroadcastReceiver

Fields Summary
private static final String
TAG
Constructors Summary
Methods Summary
public voidonReceive(android.content.Context context, android.content.Intent intent)


    
          
        String action = intent.getAction();
        Uri uri = intent.getData();
        String externalStoragePath = Environment.getExternalStorageDirectory().getPath();

        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
            // scan internal storage
            scan(context, MediaProvider.INTERNAL_VOLUME);
            
            // scan external storage if it is mounted
            String state = Environment.getExternalStorageState();
            if (Environment.MEDIA_MOUNTED.equals(state) || 
                    Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
               scan(context, MediaProvider.EXTERNAL_VOLUME);
            }
        } else {
            if (uri.getScheme().equals("file")) {
                // handle intents related to external storage
                String path = uri.getPath();
                if (action.equals(Intent.ACTION_MEDIA_MOUNTED) && 
                        externalStoragePath.equals(path)) {
                    scan(context, MediaProvider.EXTERNAL_VOLUME);
                } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE) &&
                        path != null && path.startsWith(externalStoragePath + "/")) {
                    scanFile(context, path);
                }
            }
        }
    
private voidscan(android.content.Context context, java.lang.String volume)

        Bundle args = new Bundle();
        args.putString("volume", volume);
        context.startService(
                new Intent(context, MediaScannerService.class).putExtras(args));
    
private voidscanFile(android.content.Context context, java.lang.String path)

        Bundle args = new Bundle();
        args.putString("filepath", path);
        context.startService(
                new Intent(context, MediaScannerService.class).putExtras(args));