0

I'm creating an Application to show and hide "Viber Images" folder of Viber App which is located in /viber/media/. I know I should delete and create .nomedia file in that folder and then force media scanner to scan that.

when I send a broadcast or statically using MediaScannerConnection to rescan that folder takes more than a quarter for gallery to update that folder.

I tried:

    String dir = Environment.getExternalStorageDirectory().getAbsolutePath()+"/viber/media/Viber Images/";
    File f = new File(dir);
    Uri uri = Uri.fromFile(f);
    Intent in = new Intent(Intent.ACTION_MEDIA_MOUNTED,uri);
    sendBroadcast(in);

But it's not updating the media scanner because folder is being showed in the gallery.

and I also tried:

    MediaScannerConnection.scanFile(MainActivity.this, new String[{"/storage/sdcard0/viber/media/Viber Images/"}, null, new MediaScannerConnection.OnScanCompletedListener() {

        public void onScanCompleted(String path, Uri uri) {
            Log.d("file",path+" scanned");
            Log.d("url","uri = "+uri);

        }

    });

and the logcat shows:

03-07 15:42:10.180: D/MediaScannerConnection(15267): Connected to MediaScanner
03-07 15:42:10.180: D/MediaScannerConnection(15267): Scanning file 7klwibgf7kdcbid(7mrafi7vfdrb7
03-07 15:42:10.670: D/file(15267): /storage/sdcard0/viber/media/Viber Images/ scanned
03-07 15:42:10.670: D/url(15267): uri = content://media/external/file/130512
03-07 15:42:10.670: D/MediaScannerConnection(15267): Disconnecting from MediaScanner

it seems it's updating the media scanner database But cannot effect gallery app to update its content. there is a free app called nomedia in playstore which does exactly what I want in my phone But my codes not working.

is there any method or built-in class to do so? or are there any ways to do so programmatically?

sorry for my bad english.

any answer appreciated.

4

1 回答 1

0

首先重命名文件夹。然后从媒体数据库中删除文件夹数据。然后重命名文件夹。力扫描仪扫描它...

于 2015-05-23T21:32:35.170 回答