0

I'm writing a music player that purely relies on the android content providers (MediaStore) at the moment. The problem is that the content provider doesn't always pick up all the music on the device, especially when people have strange configurations/custom roms etc.

I'm sure there is information out there about this, but I don't know what it's called or what to search for. Basically I want the device to use the content provider, but also search for media files in the background, then compare them with the content providers and add them to my adapter if they don't exist in the content provider.

Is there any open source code which does this for music or images or anything else? I'd like to see some examples.

Tim Malseed
  • 6,003
  • 6
  • 48
  • 66

1 Answers1

0

Android has a media scanner which can be triggered to re-scan. That should add the missing files to MediaStore. The simples aproach is sending a broadcast like below:

public static void triggerMediaScanner(Context context) {
    Uri data = Uri.fromFile(Environment.getExternalStorageDirectory());
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    intent.setData(data);
    context.sendBroadcast(intent);
}
zapl
  • 63,179
  • 10
  • 123
  • 154
  • Thanks for the response, but I'm talking about files which the mediaScanner doesn't pick up.. – Tim Malseed Nov 17 '12 at 04:38
  • Take some algorithm that can list files, load that list in `AsyncTask` or a custom `Loader` and put all the data in some `ArrayList` for example and feed an `ArrayAdapter` with the combined data. – zapl Nov 18 '12 at 03:00