Waiting Untill A Downloaded File Is Complete, Not Just File.exists()
I am downloading a file from the net and then reading it using a BufferedReader. Currently I download the file using DownloadManager then have this code : while (latestNumbersFile.
Solution 1:
From Android developers when download completes, DownloadManager broadcasts an intent. You can capture this "event" and handle it like:
BroadcastReceiverreceiver=newBroadcastReceiver() {
@OverridepublicvoidonReceive(Context context, Intent intent) {
Stringaction= intent.getAction();
if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
/** Do your coding here **/
}
}
};
registerReceiver(receiver, newIntentFilter(
DownloadManager.ACTION_DOWNLOAD_COMPLETE));
Source from: Vogella
Please let me know if this helps you, if it doesn't we can try anything else :)
Solution 2:
Busy-waiting is not recomended. You'd better use DownloadManager.
From Download a file with Android, and showing the progress in a ProgressDialog :
Use DownloadManager class (GingerBread and newer only) This method is awesome, you do not have to worry about downloading the file manually, handle threads, streams, etc. GingerBread brought a new feature: DownloadManager which allows you to download files easily and delegate the hard work to the system.
Post a Comment for "Waiting Untill A Downloaded File Is Complete, Not Just File.exists()"