๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’š ๊ฐœ๋ฐœ/์•ˆ๋“œ๋กœ์ด๋“œ

[์•ˆ๋“œ๋กœ์ด๋“œ] ์›น๋ทฐ ๋””๋ฒ„๊น… ์‰ฝ๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ• - Chrome inspect ์‚ฌ์šฉ๋ฒ• (3)

by devshin.kr 2021. 5. 2.
728x90
๋ฐ˜์‘ํ˜•

์•ˆ๋“œ๋กœ์ด๋“œ ์ƒ˜ํ”Œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ๋‹ค.

 

 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <WebView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/webView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

 

AndroidManifest.xml

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

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <application
        android:usesCleartextTraffic="true"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.WebViewDebugging">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

 

MainActivity.java

package com.example.webviewdebugging;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    private WebView mWebView;
    String serverUrl = "http://๋ณธ์ธIP:ํฌํŠธ/WebViewDebugging/index.html";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = findViewById(R.id.webView);

        mWebView.clearCache(true);
        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptEnabled(true);


        mWebView.addJavascriptInterface(new CustomBridge(), "BRIDGE");
        mWebView.loadUrl(serverUrl);
    }
}

 

 

CustomBridge.java

package com.example.webviewdebugging;

import android.webkit.JavascriptInterface;

public class CustomBridge {

    @JavascriptInterface
    public String androidFunc(String sInput){
        String sRet = null;

        if (sInput.compareTo("helloAndroid") == 0)
            sRet = "Hello WebView";
        else
            sRet = null;

        return sRet;
    }

}

 

 

 

Chrome://inspect ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•ด ์ •๋ฆฌํ•  ๊ฒƒ์ด๋ฏ€๋กœ ์›น๋ทฐ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…์€ ๋‹ค์Œ์—..

 

์•ˆ๋“œ๋กœ์ด๋“œ ์•ฑ์„ Run ํ•˜๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ์• ๋ฎฌ๋ ˆ์ดํ„ฐ์—์„œ ๋™์ž‘ํ•œ๋‹ค.

 

 

์•ฑ์—์„œ๋„ ์›น ํ™”๋ฉด๊ณผ ๋™์ผํ•˜๊ฒŒ ๋œฌ๋‹ค.

 

 

์ตœ์ข… ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ ์žฅ์—์„œ...



๋‹ค์Œ

[์•ˆ๋“œ๋กœ์ด๋“œ] ์›น๋ทฐ ๋””๋ฒ„๊น… ์‰ฝ๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ• - Chrome inspect ์‚ฌ์šฉ๋ฒ• (4)

 

[์•ˆ๋“œ๋กœ์ด๋“œ] ์›น๋ทฐ ๋””๋ฒ„๊น… ์‰ฝ๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ• - Chrome inspect ์‚ฌ์šฉ๋ฒ• (4)

1. ์• ๋ฎฌ๋ ˆ์ดํ„ฐ/ํœด๋Œ€ํฐ ๋‹จ๋ง๊ธฐ๋ฅผ ์—ฐ๊ฒฐํ•œ ์ƒํƒœ์—์„œ 2. Chrome ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ฃผ์†Œ์ฐฝ์— Chrome://inspect ๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค. 3. ๊ทธ๋Ÿฌ๋ฉด ์ด์ œ ๋‹ค์Œํ™” ๊ฐ™์ด Remote Target์ด ๋œฌ๋‹ค. 4. ์—ฌ๊ธฐ์„œ ํ•˜๋‹จ์˜ inspect ๋ฅผ ํด๋ฆญํ•œ๋‹ค. ๋‹ค

devshin93.tistory.com

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€