File Upload in WebView

后端 未结 19 1898
旧巷少年郎
旧巷少年郎 2020-11-22 00:28

I have been struggling to upload files from WebView since last few days and there is no progress. I googled and implemented all suggested solutions but none works, like: sol

19条回答
  •  借酒劲吻你
    2020-11-22 00:51

    I'm new to Andriod and struggled with this also. According to Google Reference Guide WebView.

    By default, a WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won't need to interact with the web page beyond reading it, and the web page won't need to interact with the user. If you actually want a full-blown web browser, then you probably want to invoke the Browser application with a URL Intent rather than show it with a WebView.

    Example code I executed in MainActvity.java.

     Uri uri = Uri.parse("https://www.example.com");
     Intent intent = new Intent(Intent.ACTION_VIEW, uri);
     startActivity(intent);
    

    Excuted

    package example.com.myapp;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import android.content.Intent;
    import android.net.Uri;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Uri uri = Uri.parse("http://www.example.com/");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
            getSupportActionBar().hide();
        }}
    

提交回复
热议问题