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)
๋๊ธ