Kevin
Kevin

Reputation: 43

Cant download in webview with Xamarin on android device

Im trying to download and upload in webview with Xamarin and when I click the upload button... Nothing happens. When it is supposed to download. Nothing happens.

How can i change this code to allow me to do so?

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

namespace Test
{
    [Activity(Label = "E-Special", MainLauncher = true, Theme = "@android:style/Theme.NoTitleBar")]

    public class MainActivity : Activity
    {

        private WebView web_view;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            web_view = FindViewById<WebView>(Resource.Id.webview);
            web_view.Settings.JavaScriptEnabled = true;
            web_view.LoadUrl("http://test.123.com/testingtster");
            web_view.SetWebViewClient(new HelloWebViewClient());
        }

        public class HelloWebViewClient : WebViewClient
        {
            public override bool ShouldOverrideUrlLoading(WebView view, string url)
            {
                view.LoadUrl(url);
                return true;
            }
        }

        public override bool OnKeyDown(Android.Views.Keycode keyCode, Android.Views.KeyEvent e)
        {
            if (keyCode == Keycode.Back && web_view.CanGoBack())
            {
                web_view.GoBack();
                return true;
            }

            return base.OnKeyDown(keyCode, e);
        }
    }
}

NOTE** That url is not the correct url. Just put it there for the forums.

Also, The upload is done VIA a simple html upload form. and the download is done VIA php to set the download. All of these work fine on my computer.. When I use my android device however, I cannot download or upload

Upvotes: 1

Views: 899

Answers (1)

Daniel Luberda
Daniel Luberda

Reputation: 7454

Wrong order of methods:

  • First web_view.SetWebViewClient(new HelloWebViewClient());

  • Then web_view.LoadUrl("http://test.123.com/testingtster");

Now, you're calling LoadUrl before you set WebViewClient.

Upvotes: 1

Related Questions