Skip to content Skip to sidebar Skip to footer

Detect If Media Scanner Running On Android

Is there any way to detect whether MediaScanner is running now or not . for example if mediascanner is running,Thread will sleep for 200 milis. thanks.

Solution 1:

Use below code.

publicstaticbooleanisMediaScannerScanning(ContentResolver cr) {
        boolean result = false;
        Cursor cursor = query(cr, MediaStore.getMediaScannerUri(),
               newString [] {MediaStore.MEDIA_SCANNER_VOLUME},
                null, null, null);
        if (cursor != null) {
            if (cursor.getCount() == 1) {
                cursor.moveToFirst();
                result = "external".equals(cursor.getString(0));
            }
            cursor.close();
        }    
        return result;
    }

It is copied from ImageManager.java of AOSP.

Post a Comment for "Detect If Media Scanner Running On Android"