1

I would like to access some of the static methods in the Debug class; part of the android.os package.

However, when I include calls to these functions javascript gives me a undefined ReferenceError; it cannot find the android package.

How do I set the search path for java packages in javascript?

4

1 に答える 1

0

これを実現するには、アクティビティで javaScriptInterface オブジェクトを作成し、それを Web ビューで設定します。webview メソッドの addJavascriptInterface() を確認してください。基本的な考え方は、JSInterface オブジェクトには Debug クラスにアクセスするためのロジックがあり、必要な値を返すというものです。

これは、SDK リファレンス ドキュメントから直接取得した基本的な例です。

class JsObject {
    @JavascriptInterface
    public String toString() { return "injectedObject"; }
}

webView.addJavascriptInterface(new JsObject(), "injectedObject");
webView.loadData("", "text/html", null);
webView.loadUrl("javascript:alert(injectedObject.toString())");
于 2013-01-31T20:38:08.580 に答える