简体   繁体   English

无法在Android设备上使用Xamarin在Webview中下载

[英]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. 我正在尝试使用Xamarin在Webview中下载和上传,并且当我单击“上传”按钮时...没有任何反应。 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. 注意**该URL不是正确的URL。 Just put it there for the forums. 只需将其放在论坛上即可。

Also, The upload is done VIA a simple html upload form. 另外,通过简单的html上载表单完成上载。 and the download is done VIA php to set the download. 并通过php设置下载完成下载。 All of these work fine on my computer.. When I use my android device however, I cannot download or upload 所有这些在我的计算机上都可以正常工作。但是,当我使用Android设备时,我无法下载或上传

Wrong order of methods: 方法顺序错误:

  • First web_view.SetWebViewClient(new HelloWebViewClient()); 第一个web_view.SetWebViewClient(new HelloWebViewClient());

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

Now, you're calling LoadUrl before you set WebViewClient. 现在,您在设置WebViewClient之前先调用LoadUrl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM