我写的应用程序加载了一些网站,但它没有加载我的网站。我已经安装了从namecheap.com购买的ssl sertificate。它现在很安全,但仍然无法加载Web视图。可能是什么问题?感谢。
代码如下;
public class WebActivity extends Activity {
public class GeoWebChromeClient extends WebChromeClient {
private static final String TAG = "MyActivity";
@Override
public void onGeolocationPermissionsShowPrompt(final String origin, final GeolocationPermissions.Callback callback) {
Log.i(TAG, "onGeolocationPermissionsShowPrompt()");
final boolean remember = false;
AlertDialog.Builder builder = new AlertDialog.Builder(WebActivity.this);
builder.setTitle("Locations Permission");
builder.setMessage("Would like to use your Current Location ")
.setCancelable(true).setPositiveButton("Allow", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// origin, allow, remember
callback.invoke(origin, true, remember);
}
}).setNegativeButton("Don't Allow", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// origin, allow, remember
callback.invoke(origin, false, remember);
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.fullscreen);
webView = (WebView) findViewById(R.id.webView2);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setGeolocationEnabled(true);
webView.setWebChromeClient(new GeoWebChromeClient());
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://edumaster.me/");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (webView.canGoBack()) {
webView.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
}
答案 0 :(得分:1)
下面的代码解决了我的第一个问题。
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});