카

안드로이드 웹뷰어

· 2025-08-08 (금) 18:32:33 · 721 · 2

링크주소에 안드로이드 스튜디오에서 다운받아서 설치 후 아래 소스를 추가하면 끝...

AI로 하니 금방 만들수 있네요..

 

MainActivity.kt

[code]

package com.seoul.seoulforeign

import android.annotation.SuppressLint
import android.os.Bundle
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import com.seoul.seoulforeign.ui.theme.SeoulForeignTheme

class MainActivity : ComponentActivity() {

    // WebView를 참조할 변수 선언
    private lateinit var webView: WebView

    @SuppressLint("SetJavaScriptEnabled")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            SeoulForeignTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    WebViewer(
                        url = "https://sir.kr",
                        modifier = Modifier.padding(innerPadding),
                        onWebViewCreated = { webView = it }
                    )
                }
            }
        }
    }

    // 뒤로가기 버튼 처리
    override fun onBackPressed() {
        if (::webView.isInitialized && webView.canGoBack()) {
            webView.goBack()
        } else {
            finish() // 앱 종료
        }
    }
}

@Composable
fun WebViewer(
    url: String,
    modifier: Modifier = Modifier,
    onWebViewCreated: (WebView) -> Unit
) {
    AndroidView(
        modifier = modifier.fillMaxSize(),
        factory = { context ->
            WebView(context).apply {
                webViewClient = WebViewClient()
                settings.javaScriptEnabled = true
                loadUrl(url)
                onWebViewCreated(this)
            }
        }
    )
}

[/code]

 

AndroidManifest.xml

[code]

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <!-- ? 인터넷 권한 추가 -->
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.SeoulForeign">

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.SeoulForeign">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

[/code]

 

구글 스토어에 업로드 할려면 비용이 들지만...

|

댓글 2개

2025-09-14 (일) 23:49:23

오! 카이루님 유튜브도 활동중인가봐요

@비버팩토리 2011. 12. 25. 가입했습니다 수입창출없는 채널

댓글을 작성하시려면 로그인이 필요합니다.

앱개발

758건
+
분류 제목 글쓴이 날짜 조회
Android 25-08-08 조회 722
Hybrid 25-06-11 조회 902
기타 23-08-07 조회 1,782
Hybrid 23-07-09 조회 2,056
Hybrid 23-04-08 조회 2,993
Android 23-04-01 조회 1,608
기타 22-12-17 조회 1,869
Hybrid 22-11-27 조회 1,509
Hybrid 22-11-27 조회 2,862
Hybrid 22-08-10 조회 1,962
IOS 22-06-27 조회 2,575
기타 22-03-15 조회 2,096
기타 22-03-01 조회 2,157
IOS 22-02-19 조회 2,016
기타
[기타]
22-02-19 조회 1,525
Hybrid 22-02-06 조회 1,932
기타 22-02-05 조회 2,275
기타 22-02-05 조회 2,019
기타 22-02-04 조회 1,867
기타 21-12-05 조회 2,340
Android 21-08-03 조회 2,749
Hybrid 21-07-04 조회 2,107
Android 21-04-16 조회 2,174
기타 21-04-14 조회 2,363
IOS 21-03-27 조회 2,068
기타 21-03-22 조회 2,119
기타 21-03-11 조회 2,478
기타 21-03-09 조회 1.1만
기타 21-03-05 조회 2,890
기타
[기타]
21-03-04 조회 2,607