네, 가능합니다. 나는 이미 사람들이 웹 사이트에 많은 자바 스크립트 주사를하기 전에. 당신은 단지 어떤 웹 사이트에 자신의 자바 스크립트를 삽입해야합니다. 예를 들어
는 WebAppInterface에서
//simple javascript to pass value from javascript to native app
String javascript = "javascript:function testHello(){return Android.hello('HAI'); testHello();}"
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//put your function in string and load the javascript when the page is finished load
view.loadUrl(javascript);
}
});
// 'Android' is your variable key for triggering the function ex: Android.hello(), Android.calculate()
// you can change to other name like 'APP', so in javascript be like this ex: APP.hello(), APP.calculate()
webview.addJavascriptInterface(new WebAppInterface(this), "Android");
//load website
webview.loadUrl(PageUrl);
는 이전
public class WebAppInterface {
Activity mContext;
public WebAppInterface(Activity c) {
mContext = c;
}
//this function will get your value from the javascript earlier.
//Android.hello('value')
@JavascriptInterface
public void hello(String value){
//you will get HAI message in here
Log.i("TAG",value);
}
}
를 주입 자바 스크립트를 감지하는 기능을 만들 수있는 곳입니다