Hybrid App - How to use JsBridge to get token ID and device info


#1

On app

  • 안드로이드 / IOS 웹뷰에서 아래 js 추가 (On app, Add js below)
mWebView.addJavascriptInterface(new JSBridge(this, mWebView), "JSBridgePlugin");

웹 (Web Front-end)

  • json object 만들어서 jsbridge을 통해 javascript 로딩 / create json object and load javascript by jsbridge
=>          final JSONObject resJson = new JSONObject();
                try {
					resJson.put("app_ver", Global.VERSION_NAME);
					resJson.put("app_nm", "WTALab");
					resJson.put("token_info", device_token);
					resJson.put("device_type", Global.OS_TYPE);
					resJson.put("device_info", device_id);
					resJson.put("device_ver", android.os.Build.VERSION.RELEASE);
				} catch (JSONException e) {
                                    e.printStackTrace();
                }
                if (!callback.isEmpty()){
                    _webView.post(new Runnable() {
                        public void run() {
                            _webView.loadUrl("javascript:"+ callback +"('" + resJson.toString() + "')");
                        }
                    });
                }

Back-end

  • jsbridge을 통해 받아올 데이터를 받을 API 적용 (Create API to get those information)
  • you can use JSBridge.callToNative(messageGetAppInfo); to get getAppInfoCallBack(response);

image