folder Scan with Intent - Android android.content

Android examples for android.content:Intent

Description

folder Scan with Intent

Demo Code

import java.io.File;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class Main {

  public static void folderScan(final Context context, String path) {
    File file = new File(path);

    if (file.isDirectory()) {
      File[] array = file.listFiles();

      for (int i = 0; i < array.length; i++) {
        File f = array[i];/* ww  w .  ja  va 2s .c  o  m*/

        if (f.isFile()) {// FILE TYPE
          String name = f.getName();

          if (name.contains(".jpg")) {
            fileScan(context, f.getAbsolutePath());
          }
        } else {// FOLDER TYPE
          folderScan(context, f.getAbsolutePath());
        }
      }
    }
  }

  public static void fileScan(final Context context, String file) {
    Uri data = Uri.parse("file://" + file);

    context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
  }

}

Related Tutorials