我正在尝试在Web视图中加载网页,我能够这样做,但是有一个允许您上传文件的按钮。当我在Android上的Chrome应用程序中加载页面并打开文件浏览器时,此按钮工作正常,在Web视图中没有任何反应。是否可以使用chrome进行Web视图,或者如何使用此按钮从Web视图中触发文件选择器?
我尝试更改网络视图选项以启用javascript等,下面是webactivity的代码:
public class WebActivity extends Activity {
Button b1;
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
b1=(Button)findViewById(R.id.button);
wv=(WebView)findViewById(R.id.webView);
//wv1.setWebViewClient(new MyBrowser());
wv.setWebChromeClient(new WebChromeClient());
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
wv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
wv.loadUrl("MY WEBSITE URL");
wv.setWebChromeClient(new WebChromeClient());
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
if (url.startsWith("tel:") || url.startsWith("mailto:")) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);
}else if(url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
}
return true;
}
});
}
});
}
}
答案 0 :(得分:1)
请尝试以下代码。
WebView wv;
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
wv.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
wv.loadUrl("YOUR URL HERE");
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
if (url.startsWith("tel:") || url.startsWith("mailto:")) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);
}else if(url.startsWith("http:") || url.startsWith("https:")) {
view.loadUrl(url);
}
return true;
}
});
wv.setWebChromeClient(new WebChromeClient());
希望这会对你有所帮助。
答案 1 :(得分:0)
默认情况下,有些选项未启用,很可能您没有使用javascript。
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);