mit Javascript in Android Webview
Ich versuche, eine Aktivität über eine Javascript-Oberfläche in meiner Webansicht zu starten. Das Beispiel zeigt einen Toast. Wie könnte ich eine Klasse anstelle eines Toasts anrufen?
<code>public class JavaScriptInterface { Context mContext; /** Instantiate the interface and set the context */ JavaScriptInterface(Context c) { mContext = c; } /** Show a toast from the web page */ public void showToast(String toast) { Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show(); } } </code>
Dies für die HTML-Seite.
<code><input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" /> <script type="text/javascript"> function showAndroidToast(toast) { Android.showToast(toast); } </code>