Bild Download über WebView

  • Antworten:6
Status-Sprüche für WhatsApp
  • Forum-Beiträge: 40

29.10.2015, 13:11:54 via Website

Hallo,
Undzwar bin ich grad dabei ein Weihnachts Special für meine App zu machen und habe einen WebView eingebaut welcher auch super funktioniert nun habe ich in meinem Webseiten Programm einen Button gemacht und ich will das über diesen Button ein Bild gedownloadet werden kann.
Kann mir da jemand helfen??????

Gruß Fredi

Antworten
Status-Sprüche für WhatsApp
  • Forum-Beiträge: 40

29.10.2015, 15:09:57 via Website

Hallo Pascal,
ich werde es nachher gleich versuchen.
Danke schonmal

Gruß Fredi

— geändert am 30.10.2015, 10:27:29

Antworten
Status-Sprüche für WhatsApp
  • Forum-Beiträge: 40

30.10.2015, 10:28:32 via Website

Hallo Pascal,
ich habe jetzt diesen Code:

 // This will handle downloading. It requires Gingerbread, though
final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

// This is where downloaded files will be written, using the package name isn't required
// but it's a good way to communicate who owns the directory
final File destinationDir = new File (Environment.getExternalStorageDirectory(), getPackageName());
if (!destinationDir.exists()) {
    destinationDir.mkdir(); // Don't forget to make the directory if it's not there
}
webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading (WebView view, String url) {
        boolean shouldOverride = false;
        // We only want to handle requests for mp3 files, everything else the webview
        // can handle normally
        if (url.endsWith(".mp3")) {
            shouldOverride = true;
            Uri source = Uri.parse(url);

            // Make a new request pointing to the mp3 url
            DownloadManager.Request request = new DownloadManager.Request(source);
            // Use the same file name for the destination
            File destinationFile = new File (destinationDir, source.getLastPathSegment());
            request.setDestinationUri(Uri.fromFile(destinationFile));
            // Add it to the manager
            manager.enqueue(request);
        }
        return shouldOverride;
    }
});

gefunden aber ich weiß nicht genau wo ich den einbauen soll, könnte ich dir den Code schicken von meiner WebView Activity und du würdest den einpflegen???

Gruß Fredi

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

30.10.2015, 13:38:08 via App

Ne für dich programmieren tu ich nicht, du sollst ja was lernen ;)

Der code kommt dahin, wo du deine WebView Initialisiertst. Zusem musst du darauf achten das du schreiberechte und die permission in der Manifest hast

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Status-Sprüche für WhatsApp
  • Forum-Beiträge: 40

30.10.2015, 13:41:09 via Website

Hey,
und welche Rechte wären das denn genau???

Antworten
Status-Sprüche für WhatsApp
  • Forum-Beiträge: 40

30.10.2015, 14:02:07 via Website

Hey,
Habs beim ersten anlauf hinbekommen :)

Antworten