Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

에이치의 모바일 앱 개발

DBFileDownload version 1.0.1 본문

Android/Android 개발 소스

DBFileDownload version 1.0.1

로이누리 2017. 12. 23. 02:18
 


/**
* Created by lsh on 2016-06-29.

* version 1.0.1
*/
public class DBFileDownload extends AsyncTask<Void, Void, String> {
private Context context;
private String serverPath, localFolderPath, localFilePath;
private int version;

public DBFileDownload(Context context, int version, String serverPath, String localFolderPath, String localFilePath) {
this.context = context;
this.version = version;
this.serverPath = serverPath;
this.localFolderPath = localFolderPath;
this.localFilePath = localFilePath;
}

private long fileSizeCheck() {
long fileSize = 0;
return fileSize;
}

/**
* 다운로드시 버전 정보와 파일 크기를 비교하여 이어받기 동작이 가능하게 한다.
*
* @param params
* @return
*/
protected String doInBackground(Void... params) {
String zipName = null;
long localFileSize, remainingFileSize, totalFileSize;
int Read;


File folder = new File(localFolderPath);
try {
if (!folder.exists()) {
folder.mkdirs()
;
}

URL mUrl = new URL(serverPath);
HttpURLConnection conn = (HttpURLConnection) mUrl.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);


int len = conn.getContentLength();
byte[] tmpByte = new byte[len];
InputStream is = conn.getInputStream();
File file = new File(localFilePath);
FileOutputStream fos = new FileOutputStream(file);
for (; ; ) {
Read = is.read(tmpByte)
;
if (Read <= 0) {
break;
}
fos.write(tmpByte
, 0, Read);
}
is.close()
;
fos.close();
conn.disconnect();

zipName = file.getName();
} catch (MalformedURLException e) {
zipName =
null;
Log.e("Error", "MalformedURLException");
} catch (SocketTimeoutException e) {
zipName =
null;
Log.e("Error", "MalformedURLException");
} catch (IOException e) {
zipName =
null;
Log.e("Error", "IOException");
e.printStackTrace();
}
return zipName;
}

protected void onPostExecute(String fileName) {
if (fileName != null) {
Log.
e("Download", "success");
new DBunzip(context, version, localFilePath, localFolderPath).execute();
} else {
Log.
e("Download", "fail");
IntroActivity.AppFinish(context);
}
}

public static boolean fileExists(String localFolderPath, String localFileName) {
boolean file_flag = false;
File[] listFiles = (new File(localFolderPath).listFiles());
for (File file : listFiles) {
if (file.getName().equals(localFileName)) {
file_flag =
true;
}
}
return file_flag;
}
}

 

'Android > Android 개발 소스' 카테고리의 다른 글

File & I/O  (0) 2017.12.23
DBunzip version 1.0.1  (0) 2017.12.23
SQLiteOpenHelper 1.0.1  (0) 2017.12.23
ripple  (0) 2017.12.23
selector  (0) 2017.12.23
Comments