In my application, I also upload photos.
When my main action (uploading images) begins, I initiate the connection of the media scanner. The download occurs sequentially, as soon as the image arrives, I save the file name in a line (with the name currentFile below) and βconnectβ the media scanner:
public class SomeActivity extends Activity implements MediaScannerConnectionClient { .... protected MediaScannerConnection mMs; .... @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); .... mMs = new MediaScannerConnection(this, this); .... } @Override public void onMediaScannerConnected() { mMs.scanFile(currentFile, null); } @Override public void onScanCompleted(String path, Uri uri) { mMs.disconnect(); } }
To start a scan, I just do:
currentFile = "/mnt/sdcard/someLocationToScan/somefile.jpg"; mMs.connect();
source share