티스토리 뷰
1. MainActivity.kt
// web view
webView = findViewById(R.id.webView)
val url = "http://surogong.man-deum.com/pages/customer/load.php"
// new page
webView.settings.javaScriptCanOpenWindowsAutomatically = false
webView.settings.setSupportMultipleWindows(false)
// html size
webView.settings.useWideViewPort = true
webView.settings.loadWithOverviewMode = true
// javascript
webView.settings.javaScriptEnabled = true
// load local images
webView.settings.loadsImagesAutomatically = true
// cache
webView.settings.cacheMode = WebSettings.LOAD_NO_CACHE
// local storage
webView.settings.domStorageEnabled = true
// allow file access
webView.settings.allowFileAccess = true
// database API
webView.settings.databaseEnabled = true
// media play
webView.settings.mediaPlaybackRequiresUserGesture = false
// allow content access with url
webView.settings.allowContentAccess = true
// location API
webView.settings.setGeolocationEnabled(true)
// client
webView.webViewClient = CustomWebViewClient(this)
webView.webChromeClient = CustomWebChromeClient(this, url)
// load URL
webView.loadUrl(url)
2. CustomWebChromeClient.kt
package com.tistory.boywin1992
import android.app.Dialog
import android.net.Uri
import android.os.Message
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
class CustomWebChromeClient(private val activity: MainActivity, private val url: String) :
WebChromeClient() {
override fun onCreateWindow(
view: WebView?,
isDialog: Boolean,
isUserGesture: Boolean,
resultMsg: Message?
): Boolean {
val newWebView = WebView(activity)
// zoom
newWebView.settings.setSupportZoom(true)
newWebView.settings.builtInZoomControls = true
newWebView.settings.displayZoomControls = true
// new page
newWebView.settings.javaScriptCanOpenWindowsAutomatically = false
newWebView.settings.setSupportMultipleWindows(false)
// html size
newWebView.settings.useWideViewPort = true
newWebView.settings.loadWithOverviewMode = true
// javascript
newWebView.settings.javaScriptEnabled = true
// load local images
newWebView.settings.loadsImagesAutomatically = true
// cache
newWebView.settings.cacheMode = WebSettings.LOAD_NO_CACHE
// local storage
newWebView.settings.domStorageEnabled = true
// allow file access
newWebView.settings.allowFileAccess = true
// database API
newWebView.settings.databaseEnabled = true
// media play
newWebView.settings.mediaPlaybackRequiresUserGesture = false
// allow content access with url
newWebView.settings.allowContentAccess = true
// location API
newWebView.settings.setGeolocationEnabled(true)
// client
val dialog = Dialog(activity)
dialog.setContentView(newWebView)
dialog.show()
newWebView.webViewClient = CustomWebViewClient(activity)
newWebView.webChromeClient = object : WebChromeClient() {
override fun onCloseWindow(window: WebView?) {
dialog.dismiss()
}
}
(resultMsg?.obj as WebView.WebViewTransport).webView = newWebView
resultMsg.sendToTarget()
// load URL
newWebView.loadUrl(url)
return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg)
}
}
'android' 카테고리의 다른 글
how to change color of status bar from android (0) | 2022.05.23 |
---|---|
[안드로이드 / 코틀린] 위치 권한 얻는 방법 (0) | 2022.05.23 |
how to remove title from android app (0) | 2022.05.23 |
[안드로이드] EditText 자동 포커싱 방지 / 키보드 자동으로 올라오는 현상 방지 (0) | 2022.05.22 |
그라데이션 효과 적용하는 방법 (0) | 2022.05.22 |
- Total
- Today
- Yesterday
- 외부 브라우저
- 웹뷰
- web chrome view
- StringWriter
- 화면 방향 고정
- web view settings
- logtag
- custom web view
- Inputmode
- 영문 키보드
- screenorientation
- web view
- Android
- new project
- 화면 고정
- 로그캣
- logcat
- 코틀린
- javaClass
- simpleName
- android studio
- 클래스 이름
- permissions
- check permissions
- 안드로이드
- create project
- defaultInputmode
- andorid
- create new project
- kotlin
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |