android webview JS 调用Android实例
JS代码: <a class="inmx-btn" href="javascript:;" onclick="getwifi()">刷新</a></h3>function getwifi(){var wifiname=window.app.getConn
JS代码: <a class="inmx-btn" href="javascript:;" οnclick="getwifi()">刷新</a></h3>
function getwifi(){
var wifiname=window.app.getConnectWifiSsid();
$("#wifi_name").html(wifiname);
}
Android的代码: mWebView.addJavascriptInterface(new MyJSInterface(),"app");
class MyJSInterface
{
@JavascriptInterface
public void androidMethod() //提供给js调用的方法
{
Toast.makeText(getApplicationContext(), "调用这个方法", Toast.LENGTH_LONG).show();
}
@JavascriptInterface
public String getConnectWifiSsid(){
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
Log.d("wifiInfo", wifiInfo.toString());
Log.d("SSID",wifiInfo.getSSID());
return wifiInfo.getSSID();
}
}
更多推荐
所有评论(0)