0
私はこのスニペットコードを使用して、サーバーからmp4ファイルをダウンロードしています。通常、ファイルは正しくダウンロードされますが、 がダウンロード処理を自動的に停止します。プログレスバーのストップをインクリメントします。ダウンロードを停止するカーネルプロセスはありますか?アンドロイドアプリケーションのサーバーからファイルをダウンロードする際の問題
//+++++++++= FUnction Call ++++++++++++++++
DOWNLOAD_FILE_NAME = "demo.mp4";
grabURL("mp4 file server url");
//+++++++++++++++++++++++++++++++++++++++++
public void grabURL(String url) {
new GrabURL().execute(url);
}
private class GrabURL extends AsyncTask<String, Void, Void> {
private final HttpClient Client = new DefaultHttpClient();
private String Content;
private String Error = null;
private ProgressDialog Dialog = new ProgressDialog(SlideShow.this);
protected void onPreExecute() {
showDialog(DIALOG_PROGRESS);
mProgressDialog.setProgress(0);
}
protected Void doInBackground(String... url) {
int count;
try {
URL url2 = new URL(url[0]);
URLConnection conexion = url2.openConnection();
conexion.setUseCaches(true);
conexion.connect();
// this will be useful so that you can show a tipical 0-100% progress bar
int lenghtOfFile = conexion.getContentLength();
mProgressDialog.setMax(lenghtOfFile);
// downlod the file
InputStream input = new BufferedInputStream(url2.openStream());
OutputStream output = new FileOutputStream(DOWNLOAD_FILE_NAME);
byte data[] = new byte[1024];
while ((count = input.read(data)) != -1) {
mProgressDialog.incrementProgressBy(data.length);
output.write(data, 0, count);
}
output.close();
input.close();
} catch (Exception e) {}
return null;
}