我正在使用 android webview 应用程序访问网站。在提交部分有一个名为上传图片的按钮(仅对用户显示)。当我尝试从 google chrome 或我的 PC 上传图像时,没有问题,但是当我尝试从 webView 应用程序上传图像时,当我单击上传按钮时,什么也没有发生。我知道我需要获得许可,而且我已经获得了我需要的一切。这是我的代码,但我不知道我错过了什么地方出了什么问题?我会感谢你们的帮助。
public class SubmitProperty extends AppCompatActivity {
private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE=1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_submit);
WebView webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new myWebClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.setWebChromeClient(new WebChromeClient() {
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("image/*");
SubmitProperty.this.startActivityForResult(Intent.createChooser(i, "File Chooser"),FILECHOOSER_RESULTCODE);
}
});
webView.getSettings().setDisplayZoomControls(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.loadUrl("http://asemanhome.com/submit-property/");
}
public class myWebClient extends WebViewClient
{ …
Run Code Online (Sandbox Code Playgroud)