Skip to content

Commit

Permalink
修改Android BUG,完善README
Browse files Browse the repository at this point in the history
  • Loading branch information
gwpp committed Feb 10, 2018
1 parent 318a4df commit 29dbd20
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions Android/app/src/main/assets/jsinterface.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
*/
function showResponse(response) {
$('#response').text(response);
return response;
}

$(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class JsInterfaceLogic {
private BaseFragment mFragment;
Expand All @@ -28,7 +27,7 @@ public void logout() {

@JavascriptInterface
public String getLoginUser() {
return new JSONObject(new HashMap(4){{
return new JSONObject(new HashMap(4) {{
put("user_id", 666);
put("username", "你就说6不6");
put("sex", "未知");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.ValueCallback;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Expand Down Expand Up @@ -130,6 +131,11 @@ public void renderUrl(@NonNull String url) {

@Override
public void execJavaScript(@NonNull String js) {
mWebView.evaluateJavascript("javascript:"+js, null);
mWebView.evaluateJavascript(js, new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
showNativeMessage("调用JS方法后得到的返回值是:" + s);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.ValueCallback;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Expand Down Expand Up @@ -75,6 +76,11 @@ public void renderUrl(@NonNull String url) {

@Override
public void execJavaScript(@NonNull String js) {
mWebView.evaluateJavascript(js, null);
mWebView.evaluateJavascript(js, new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
showNativeMessage("调用JS方法后得到的返回值是:" + s);
}
});
}
}
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# jsnative-ios
# jsinterface

- iOS Demo OK
- Android Demo 正在开发中
#### 说明
本项目是为我们系列博客做的Demo,Demo中包括了Android <=> Js 、iOS <=> Js 交互的所有常见方式,包括拦截跳转、JSContext、@JavaScriptInterface、JSBridge等等。有兴趣的朋友可以下载下来看看

#### 博客地址:
- [《App与Js交互(一)iOS》](https://www.jianshu.com/p/13b65557c27f)
- [《App与Js交互(二)Android》](https://www.jianshu.com/p/5a511e03a7fa)
- [《App与Js交互(三)Android、iOS通用解决方案推荐》](https://www.jianshu.com/p/6224f429ce87)

#### Demo 预览
![iOS Demo](ios-home.png) ![Android Demo](android-home.png)
Binary file added android-home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ios-home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 29dbd20

Please sign in to comment.