Initialize MediaScanner at Beginning of Android Program
<p>I have an Android program that starts off by loading some of the user's media. Occasionally the program crashes -- both on an emulator and on an actual phone. I've found this is because sometimes media only become available to the program after the activity has been running for a while. </p>

<p>When this happens, here is the order of the typical log output:</p>

<ol>
<li>DEBUG/MediaScanner(166): opendir /system/media/ failed, errno: 2    &lt;--PROGRAM ERROR HERE</li>
<li>DEBUG/MediaScannerService(166): done scanning volume internal</li>
<li>DEBUG/MediaScannerService(166): start scanning volume external</li>
<li>VERBOSE/MediaProvider(166): /sdcard volume ID: 45454545</li>
<li>VERBOSE/MediaProvider(166): Attached volume: external</li>
<li>DEBUG/MediaScannerService(166): done scanning volume external  &lt;-- THIS IS IN MIDDLE OF PROGRAM</li>
</ol>

<p>The program has an error at #1 because it tried to load media that wasn't available until #6.</p>

<p>Is there any way to force Android to finish the MediaScannerService at the beginning of the program?</p>

<p>Alternatively, is there any way to check when the MediaScannerService has finished scanning?</p>

<p>Thank you.</p>
