رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
مشکل دانلود فایل با حجم بالا در اندروید
#1
سلام خسته نباشیــد
میخواستم بدونم میشه کاری کرد که فایل های زیپ دو پارتی رو دانلود و در یک پوشه استخراج کنیم؟
یعنی دوتا فایل با اسم part1.zip و part2.zip رو میشه دانلود واستخراج کرد؟
پاسخ
تشکر شده توسط:
#2
بله امکانش هست. فقط الان مشکل شما توی دانلوده یا اکسترکت ؟
پاسخ
تشکر شده توسط:
#3
مشکل من شامل استخراج میشه.
نمیدونم چرا بالای 500 مگ رو چرا تو اپ نمیشه دانلود کرد؛مجبورم الان به دو پارت تبدیل کنم:(
پاسخ
تشکر شده توسط:
#4
استاد لطفا زاهنمایی کنید ؛فقط همین مشکل برنامم مونده
پاسخ
تشکر شده توسط:
#5
http://stackoverflow.com/questions/16142...in-android

http://stackoverflow.com/questions/33829...in-android

کلاٌ سرچ کنید How to extract multipart zip files in android programmatically
پاسخ
تشکر شده توسط: reza7z
#6
متاسفانه هیچکدوم برای حل مشکل من نبود.
part1.zip.001 و part1.zip.002
میخوام استخراج کنم؛لطفا کمی زیر دیپلم توضیح بدید،چه کتابخونه ای لازم هست
پاسخ
تشکر شده توسط:
#7
(22-08-1395، 02:35 ب.ظ)reza7z نوشته: متاسفانه هیچکدوم برای حل مشکل من نبود.
part1.zip.001 و part1.zip.002
میخوام استخراج کنم؛لطفا کمی زیر دیپلم توضیح بدید،چه کتابخونه ای لازم هست

up
:|
استاد گیرم لطفا راهنمایی کنید؟
پاسخ
تشکر شده توسط:
#8
استاد اصلا پارت نکنیم
چجوری فایلی با حجم 500 مگ رو دانلود کنم؟!
الان این کد من

@Override
void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {

    mBuilder.setContentText("در حال برقراری ارتباط با سرور");
}

@Override
protected void connected(BaseDownloadTask task, String etag, boolean isContinue, int soFarBytes, int totalBytes) {
    mBuilder.setProgress(100, 0, false);
    mNotifyManager.notify(id, mBuilder.build());

}

@Override
protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
     //Log.i("TAG","soFarBytes : "+soFarBytes+"totalBytes : "+totalBytes);
    mBuilder.setContentText("در حال دانلود فایل ..." + "سرعت : " + task.getSpeed() + " K/s");
    int newsoFar = soFarBytes / 1000;
    int newtotalBytes = totalBytes / 1000;

    Log.i("LOG", (newsoFar * 100) / newtotalBytes + " " + "so: " + soFarBytes + " total : " + totalBytes);

     mBuilder.setProgress(100, Integer.parseInt((newsoFar * 100) / newtotalBytes + ""), false);
    mNotifyManager.notify(id, mBuilder.build());
}


فایل با حجم 300 مگ دانلود میشه بالاتر از اون تو برقراری ارتباط با سرور گیر میکنه!یعنی بالاتر از 300 مگ رو نمیکشه
پاسخ
تشکر شده توسط:
#9
میشه با روش دانلودخودتون راهنمایی کنید؟
پاسخ
تشکر شده توسط:
#10
سلام. من از این کلاس که خودم نوشتم استفاده میکنم:
import android.os.Environment;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

public class Downloader {
    public static final String PATH_TEMP;
    public static final String PATH_FINAL;
    public static final int BUFFER_SIZE = 8 * 1024;
    public static ArrayList<String> urls = new ArrayList<>();

    static {
        PATH_TEMP = Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp/";
        PATH_FINAL = Environment.getExternalStorageDirectory().getAbsolutePath() + "/final/";
    }

    public static void addToDownloadList(String url) {
        if (!urls.contains(url)) {
            urls.add(url);
            download(url);
        }
    }

    private static void download(final String url) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String fileName = getFileName(url);

                String pathTemp = PATH_TEMP + fileName;
                String pathFinal = PATH_FINAL + fileName;

                try {
                    URL httpURL = new URL(url);
                    HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection();
                    connection.setRequestMethod("GET");
                    connection.setDoOutput(true);
                    connection.connect();

                    int totalSize = connection.getContentLength();

                    File file = new File(pathTemp);
                    if (file.exists()) {
                        file.delete();
                    }

                    FileOutputStream outputStream = new FileOutputStream(pathTemp);
                    InputStream inputStream = connection.getInputStream();

                    byte[] buffer = new byte[BUFFER_SIZE];

                    int len;
                    int downloadedSize = 0;
                    int percent = 0;
                    while ((len = inputStream.read(buffer)) > 0) {
                        outputStream.write(buffer, 0, len);
                        downloadedSize += len;
                        percent = (int) (100.0f * (float) downloadedSize / totalSize);
                    }
                    if (percent == 100) {
                        file = new File(pathFinal);
                        if (file.exists()) {
                            file.delete();
                        }
                        copyFile(pathTemp, pathFinal);
                    }
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    private static void copyFile(String source, String destination) {
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        try {
            inputStream = new FileInputStream(source);
            outputStream = new FileOutputStream(destination);
            byte[] buffer = new byte[BUFFER_SIZE];
            int len;
            while ((len = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.flush();
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private static String getFileName(String path) {
        String[] parts = path.split("/");
        return parts[parts.length - 1];
    }
}

درصورت نیاز میتونین کلاس رو گسترش بدین و امکانات دلخواه رو بهش اضافه کنین. نحوه‌ی استفاده هم خیلی راحته:
Downloader.addToDownloadList("http://www.ncis.ir/Resume.pdf");
پاسخ
تشکر شده توسط: alirezaey , reza7z




کاربران در حال بازدید این موضوع: 2 مهمان