Hallo nochmal,
der Titel sagt schon alles, ich habe schon viel gegoogelt und etwas gefunden, leider möchte er einfach nicht downloaden.
Hier ist mal der Code:
Der Dialog öffnet sich zwar, aber es tut sich garnix, der ProgressDialog ist immer auf 0.
Hab ich Vielleicht etwas falsch gemacht?
Ich bedanke mich schonmal im Voraus.
MfG
der Titel sagt schon alles, ich habe schon viel gegoogelt und etwas gefunden, leider möchte er einfach nicht downloaden.
Hier ist mal der Code:
Java:
public void updateData(){
final String file_url = this.getString(R.string.file_url);
final ProgressDialog myProgress = new ProgressDialog(this);
myProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
myProgress.setMessage("Videodateien werden heruntergeladen.");
myProgress.show();
new Thread(new Runnable(){
public void run(){
try {
URL url = new URL(file_url);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File SDCardRoot = Environment.getExternalStorageDirectory();
File file = new File(SDCardRoot,"filename.rar");
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
int totalSize = urlConnection.getContentLength();
myProgress.setMax(totalSize);
int downloadedSize = 0;
byte[] buffer = new byte[1024];
int bufferLength = 0;
int progress = 0;
while ( (bufferLength = inputStream.read(buffer)) != -1 ) {
fileOutput.write(buffer, 0, bufferLength);
downloadedSize += bufferLength;
progress = downloadedSize;
myProgress.setProgress(progress);
}
fileOutput.close();
myProgress.dismiss();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
Der Dialog öffnet sich zwar, aber es tut sich garnix, der ProgressDialog ist immer auf 0.
Hab ich Vielleicht etwas falsch gemacht?
Ich bedanke mich schonmal im Voraus.
MfG