download file by webview

mfaridi1mfaridi1 mohammad faridiGBMember

hi plase help download file in webview code java

webview.setDownloadListener(new DownloadListener() {
      public void onDownloadStart(String url, String userAgent,
              String contentDisposition, String mimetype,
              long contentLength) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
      }
  });
plase code mono for android download file

Posts

  • ChrisHonselaarChrisHonselaar Chris Honselaar NLBeta ✭✭✭

    I think something like:

    public class MyDownloadListener : IDownloadListener
    {
        public void Dispose() { }
    
        public IntPtr Handle { get; private set; }
    
        public void OnDownloadStart(string url, string userAgent, string contentDisposition, string mimetype, long contentLength)
        {
            // do whatever you want here
        }
    }
    

    And then use it as:

    webView.SetDownloadListener(new MyDownloadListener());
    

    You will probably also need to call SetWebViewClient.

  • m1faridim1faridi mfaridi mfaridi AFMember

    Hi, thanks for the answer but can you make me an example

  • mfaridi1mfaridi1 mohammad faridi GBMember

    tanks chris I click on the link to download the browser, but I can not make plase help

  • ChrisHonselaarChrisHonselaar Chris Honselaar NLBeta ✭✭✭

    You flagged my message for abuse?

  • m1faridim1faridi mfaridi mfaridi AFMember
    edited May 2013

    no no I was wrong. I'm so sorry

  • ChrisHonselaarChrisHonselaar Chris Honselaar NLBeta ✭✭✭

    No worries :)

    What is the issue you are having exactly? I don't have time to write a complete example unfortunately, but you can find a lot of those if you just Google, although you will have to change them a little bit for Xamarin.Android. The snippet I gave above should get you started at least.

  • m1faridim1faridi mfaridi mfaridi AFMember
    edited May 2013

    My problem with the file download

    using System;

    using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; using Android.Webkit;

    namespace AndroidApplication4 { [Activity(Label = "AndroidApplication4", MainLauncher = true, Icon = "@drawable/icon")] public class Activity1 : Activity {

       public class MyDownloadListener : IDownloadListener
                {
                      public void Dispose() { }
    
                          public IntPtr Handle { get; private set; }
    
                          public void OnDownloadStart(string url, string userAgent, string contentDisposition, string mimetype, long contentLength)
                }
        // do whatever you want here
    
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
    
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
    
    
            // Get our button from the layout resource,
            // and attach an event to it
    
            WebView webview = FindViewById<WebView>(Resource.Id.webView1);
            Button button = FindViewById<Button>(Resource.Id.button1);
    
    
            webview.Settings.JavaScriptEnabled = true;
            webview.SetWebViewClient(new WebViewClient());
    

    // download file webview.LoadUrl("http://dl3.downloadha.com/Reza/SoftWare/IDM 6.15 Build 5 Final (www.Downloadha.com).rar");

                              webview.SetDownloadListener(new MyDownloadListener());
        }
    }
    

    }

    please help

  • ChrisHonselaarChrisHonselaar Chris Honselaar NLBeta ✭✭✭

    What is it that you are trying to achieve exactly? Why would you programmatically start a download on the WebView, and then programmatically intercept that?

    Are you sure you are not actually looking for WebClient.DownloadFile()? If you simply want to download a file, that's all you need.

  • m1faridim1faridi mfaridi mfaridi AFMember

    yes Download the file from the site

  • ChrisHonselaarChrisHonselaar Chris Honselaar NLBeta ✭✭✭

    Ok, then all you need is WebClient, example here.

    You do not need (and should not use) WebView for programmatic downloads/uploads/requests.

  • m1faridim1faridi mfaridi mfaridi AFMember

    You could actually manipulate the correct me for android please help example

  • ChrisHonselaarChrisHonselaar Chris Honselaar NLBeta ✭✭✭

    Just remove all of that DownloadListener and WebView stuff, you do not need any of that. Just follow the example link I posted above, it's ready to run.

  • m1faridim1faridi mfaridi mfaridi AFMember

    shere link for app downloads

  • m1faridim1faridi mfaridi mfaridi AFMember

    tanks

Sign In or Register to comment.