将变量从镀铬转移到WebView



所有WebView文件上传教程/指南/文章显示我使用 Web Chromeclient this

myWebView.setWebChromeClient(new WebChromeClient() {
        @Override
         public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,              FileChooserParams fileChooserParams) {
                 mFilePathCallback = filePathCallback;
                // Launch Intent for picking file
                return true;
         }
});

因此,在这里我们不使用自己的 Web Chromeclient 从单独的文件中扩展了原始文件,我们只是直接将New One声明为 setWebChromeClient 参数覆盖了所有必要的方法,并且它工作很酷,但是如果我的客户在单独的文件中怎么办?

如果我的 mainActivity 类看起来像

import com.example.app.ModifiedWebViewClient;

使用后者

webView.setWebChromeClient(new ModifiedWebChromeClient());

和我的 modifiedwebchromeclient

public class ModifiedWebChromeClient extends WebChromeClient {
     ....

我将如何通过 filePathCallback inshowfilechooser 回到 mainActivity

使用静态变量访问该值。声明主活性中的静态变量,将FilePathCallback值分配给该静态变量。

  MainActivity.staticvariable=filePathCallback; 

最新更新