Hi, I was looking through various parts of my code to try to figure out what is happening, but it seems I cannot figure it out. The following code should load two files, one of which is called “clientraw”, and one is called “clientrawextra”, but for some reason, when I look in the directory, there are 2 versions of each file “clientraw ... 1 ..." "clientrawextra ... 1 ..."
Therefore, it seems that it downloads files several times, and I have no idea why?
Thanks in advance!
distance dis = new distance(); dis.findURL(value); String url = dis.findURL(value); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "clientraw.txt"); // get download service and enqueue file DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request); ///////////////////////////////////////////////////// distance disextra = new distance(); disextra.findextra(value); String urlextra = disextra.findextra(value); DownloadManager.Request requestextra = new DownloadManager.Request(Uri.parse(urlextra)); // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { requestextra.allowScanningByMediaScanner(); } requestextra.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "clientrawextra.txt"); manager.enqueue(requestextra); mDownload = new DownLoadComplte(); registerReceiver(mDownload, new IntentFilter( DownloadManager.ACTION_DOWNLOAD_COMPLETE));
And the broadcast receiver ...
private class DownLoadComplte extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equalsIgnoreCase( DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { Intent myIntent = new Intent(splash.this, MainActivity.class); myIntent.putExtra("key", value);
source share