Android - Async downloads all files under one name -
I use Async to download all files of one area (walkfaster.mod adventure.mod and climbing.mod) I am doing ) And the links are downloading the correct file, but it saves it under all the name walkfaster.mod. This is my code:
package com.dogger20011.mcpemodlocater; Public class v090 activity expansion {public static ending end DIALOG_DOWNLOAD_PROGRESS = 0; Private button startBtn; Personal progress DIOLOG MPEGDLOG; Override public null on @reate (bundle saved instainstate) {super.naught (savedinstenstate); SetContentView (R.layout.v090); StartBtn = (button) FindById (R.id.button2); StartBtn.setOnClickListener (New OnClickListener) {public void onClick (see v) {startdownload (v);}}); StartBtn = (button) Find VVBIID (R.B.ton3); StartBtn.setOnClickListener (New OnClickListener) {public void onClick (see v) {startdownload (v);}}); StartBtn = (button) Search ViewById (R.id.button4); StartBtn.setOnClickListener (New OnClickListener) {public void onClick (see v) {startdownload (v);}}); } Private Zero startDownload (see v) {switch (v.getId ()) {case R.id.button2: string url = "https://docs.google.com/uc authuser = 0 & amp; id = 0B6ocq4LWhNJkZ2gyazVqNlZjcDg & Amp; Export = Download "; New DownloadFileAsync () Executed (url); break; Case R.id.button3: String URL1 = "? Https://docs.google.com/uc authuser = 0 & amp; ID = 0B6ocq4LWhNJkMmUwcWhraU5SUkU & Export = Download"; New DownloadFileAsync () Execute (url1); break; Case R.id.button4: String url2 = "https://docs.google.com/uc? Authuser = 0 & amp; ID = 0B6Kock4LWJNX01UGLXCFCU 0 and Export = Download"; New DownloadFileAsync () Executed (url2); break; }} @ Override Protected Dialogue On Create Dialogue (Int ID) {Switch (ID) {Case Dialog_datide_progress: mProgressDialog = New Progress DiLoOgh (this); MProgressDialog.setMessage ("download file .."); MProgressDialog.setProgressStyle (ProgressDialog.STYLE_HORIZONTAL); MProgressDialog.setCancelable (wrong); MProgressDialog.show (); Return mProgressDialog; Default: return zero; }} Class DownloadFileAsync Expands AsyncTask & lt; String, string, string & gt; {@Override Secure Zero on PreExecute () {super.onPreExecute (); ShowDialog (DIALOG_DOWNLOAD_PROGRESS); } @ Override protected string doInBackground (string ... aurl) {int count; {URL URL} Try New URL (Error [0]); URL Connection Connection * url.openConnection (); Conexion.connect (); Int lenghtOfFile = conexion.getContentLength (); Log D. ("ANDRO_ASYNC", "file length:" + Langffile); InputStream input = new BufferedInputStream (url.openstream ()); Outputstream output = new file output stream ("/sdcard/Android/data/com.snowbound.pockettool.free/Patches/walkfaster"); Byte data [] = new byte [1024]; Long total = 0; While ((count = input.read (data))! = -1) {total + = count; PublishProgress ("" + (int) ((total * 100) / lenghtOfFile)); Output.write (data, 0, count); } Output.flush (); Output.close (); Input.close (); } Hold (exception e) {} return tap; } Execute Private Zero (URL URL, URL URL 1) {/ TODO Auto-Generated Method Stub} Public Zero myClickHandler (see V) {intent i3 = new intent (v090.this, server_255.class); StartActivity (i3); }}}
Why do not you do anything like this, pass the file name Url < With code> new DownloadFileAsync (). Execute (url, "myFile1"); where myFile1 is the name of the file. You can then retrieve this name using aurl [1] using the doInBackground method. This sample is
Private Zero Start Download (see V) {Switch (v.getId ()) {Case R.D. button 2: string URL = "Https://docs.google.com/uc?Authuser= 0 and amp; id = 0B6ocq4LWhNJkZ2gyazVqNlZjcDg and export = download"; New DownloadFileAsync () Execute (url, "myFile1"); break; Case R.id.button3: String URL1 = "? Https://docs.google.com/uc authuser = 0 & amp; ID = 0B6ocq4LWhNJkMmUwcWhraU5SUkU & Export = Download"; New DownloadFileAsync () Execute (url1, "myFile2"); break; Case R.id.button4: String url2 = "https://docs.google.com/uc? Authuser = 0 & amp; ID = 0B6Kock4LWJNX01UGLXCFCU 0 and Export = Download"; New DownloadFileAsync () Execute (url2, "myFile3"); break; }} and replace this line
OutputStream output = new FileOutputStream ("/sdcard/Android/data/com.snowbound.pockettool.free/ Patches / move fast "); OutputStream output = new FileOutputStream ("/sdcard/Android/data/com.snowbound.pockettool.free/Patches/"+aurl [ 1]);
Comments
Post a Comment