Category Archives: Dev

android webview与native通信

  1. native调用js:
    1. webview.loadUrl("javascript:myTestFunction();");
  2. js调用native:
    1. private classJavaScriptInterface{
    2. public void callFromJS(){
    3. Toast.makeText(WebViewActivity.this,"JavaScript interface call",Toast.LENGTH_LONG).show();
    4. }
    5. }
    1. webView.addJavascriptInterface(newJavaScriptInterface(),"interface");
    1. <button onclick="interface.callFromJS()">JavaScript interface</button>

http://www.caphal.com/android/communication-between-application-and-webview/

 

ios webview和native通信

  • native 调用js方法:
    NSString*returnvalue =[webView stringByEvaluatingJavaScriptFromString:@"your javascript code string here"];
  • js调用 native:
  • window.location.href = yourscheme://callfunction/parameter1/parameter2?parameter3=value

     

    -(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
       NSURL *URL =[request URL];if([[URL scheme] isEqualToString:@"yourscheme"]){// parse the rest of the URL object and execute functions
    }}

http://stackoverflow.com/questions/9473582/ios-javascript-bridge

adb 无响应

问题:在mac下,adb devices等命令没有任何输出。

解决方案:因为adb server的端口被占用。可以重新给adb server指定端口。


$ ANDROID_ADB_SERVER_PORT=6789 adb devices

 

#update: sep 11,2014

但是更好的方案是,找出占用端口的进程。
adb 默认端口5037,

sudo lsof -Pi :5037

then KILL them