Untitled
unknown
java
3 years ago
2.4 kB
19
Indexable
package com.hello.webview2; import android.annotation.TargetApi; import android.content.DialogInterface; import android.net.http.SslError; import android.os.Build; import android.os.Bundle; import android.webkit.PermissionRequest; import android.webkit.SslErrorHandler; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; //웹뷰 로드시 SSL 인증서 에러 방지 public class MainActivity extends AppCompatActivity { private WebView webView1; private WebSettings mWebSettings; @RequiresApi(api = Build.VERSION_CODES.O) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView view = (WebView) this.findViewById(R.id.webview); WebSettings webSettings = webView1.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setLoadsImagesAutomatically(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setUseWideViewPort(true); webSettings.setSafeBrowsingEnabled(false); webSettings.setGeolocationEnabled(true); webSettings.setDomStorageEnabled(true); view.loadUrl("https://choco.kr:3000"); } public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("이 사이트의 보안 인증서는 신뢰하는 보안 인증서가 아닙니다. 계속하시겠습니까?"); builder.setPositiveButton("계속하기", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.proceed(); } }); builder.setNegativeButton("취소", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handler.cancel(); } }); final AlertDialog dialog = builder.create(); dialog.show(); } }
Editor is loading...