V tomto kóde vraciam reťazec. Chcem tento reťazec uložiť v činnosti systému Android. Ako môžem volať funkciu JavaScript a získať návratnú hodnotu z činnosti systému Android?
<script type="text/javascript">
function gettext(){
return "http://192.168.1.11/bmahtml5/images/specs_larg_2.png";
};
function button_clicked(){
window.location="ios:nativecall";
};
</script>
odpovede:
0 pre odpoveď č. 1tu je jednoduchý:
WebAppInterface.java
public class WebAppInterface
{
Context mContext;
/** Instantiate the interface and set the context */
WebAppInterface(Context c)
{
mContext = c;
}
public void storeText(String text)
{
//TODO save text
Toast.makeText(mContext, text, Toast.LENGTH_LONG).show();
}
}
WebView webview=(WebView)findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(new WebAppInterface(this), "Android");
Teraz môžete zavolať túto metódu v html, pozrite si ju
<script type="text/javascript">
function saveFunction(text)
{
Android.storeText(text);
}
</script>