1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| ...... // 添加JavaScript桥 mWebView.addJavascriptInterface(new JSBridge(this, mWebView), "Demo"); ...... // JSBridge类 class JSBridge { ...... /** * 分享 * * @param title * @param content * @param thumb_url * @param url */ @JavascriptInterface @JavascriptInterface public void horizonShare(final String title, final String content, final String thumb_url, final String url) { //do share ShareUtils.share(ctx, title, content, thumbUrl, url, new PlatformActionListener() { @Override public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) { mWebView.post(new Runnable() { @Override public void run() { mWebView.loadUrl("javascript:onShareSuccess()"); } }); }
@Override public void onError(Platform platform, int i, Throwable throwable) { if (BuildConfig.DEBUG) { throwable.printStackTrace(); } mWebView.post(new Runnable() { @Override public void run() { mWebView.loadUrl("javascript:onShareFailed()"); } }); }
@Override public void onCancel(Platform platform, int i) { mWebView.post(new Runnable() { @Override public void run() { mWebView.loadUrl("javascript:onShareFailed()"); } }); } }); } ...... }
|