Hallo Leute,
Ich versuche eine Datei herunterzuladen.
Ich versuche es aktuell so:
Java
public void DownloadPDF(String DownloadUrl, String fileName) {
try {
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
Date today = Calendar.getInstance().getTime();
String reportDate = df.format(today);
File currentf = new File(Environment.getExternalStorageDirectory() + "/asrplus/" + reportDate + "/" + fileName);
URL url = new URL(DownloadUrl);
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(5000);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos = new FileOutputStream(currentf);
fos.write(baf.toByteArray());
fos.flush();
fos.close();
} catch (IOException e) {
Log.d("DownloadManager", "Error: " + e);
}
}
Alles anzeigen
Berechtigungen
Code
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
So schmiert die App aber leider ab
mfg ternes3