PDA

View Full Version : دانلود فایل در اندروید با قابلیت مکث و شروع دوباره - سوال



Hamed_razor
دوشنبه 27 اردیبهشت 1395, 15:08 عصر
دوستان سلام
من با این کد میتونم فایلی رو که میخوام دانلود کنم ولی نمیدونم چطور قابلیت Stop و Pause بهش اضافه کنم
مثلا یه بخش از فایل رو بتونه بعد دانلود کنه





int count;
try {
URL url = new URL("http://0up.ir/do.php?downf=Zire-Baran-Bayad-Raft.mp3");

URLConnection conection = url.openConnection();

conection.connect();
// this will be useful so that you can show a tipical 0-100% progress bar
int lenghtOfFile = conection.getContentLength();

// download the file
InputStream input = new BufferedInputStream(url.openStream(), 8192);

// Output stream
OutputStream output = new FileOutputStream(Environment.getExternalStorageDir ectory() + "/audio.mp3");

byte data[] = new byte[1024];

long total = 0;

while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress("" + (int) ((total * 100) / lenghtOfFile));

// writing data to file
output.write(data, 0, count);
}

// flushing output
output.flush();

// closing streams
output.close();
input.close();

} catch (Exception e) {
Log.i("MSG: ", e.toString());
}

return null;

saeidcd
چهارشنبه 29 اردیبهشت 1395, 14:06 عصر
ببین این نمونه برنامه بدردت میخوره

http://uplod.ir/r8pe88zrg6cz/AndroidDownLoad.rar.htm

Hamed_razor
پنج شنبه 06 خرداد 1395, 12:53 عصر
ممنون مشکل حل شد
http://www.java-tips.org/java-se-tips-100019/15-javax-swing/1391-how-to-create-a-download-manager-in-java.html