달팽이웰니스

Web2App 호출 본문

tech

Web2App 호출

SM_SNAIL 2025. 1. 22. 11:17

Web2App 호출

ref.
1. 연동 방식
 
호출 그림
  • WebView에 웹 페이지를 띄워 Web to App 통신 후에 기존 샘플처럼 App to App 통신하는 방식.
 
Ref.

WebView에서 웹 앱 빌드  |  Android Developers

 

WebView에서 웹 앱 빌드  |  Android Developers

이 페이지는 Cloud Translation API를 통해 번역되었습니다. WebView에서 웹 앱 빌드 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. WebView를 사용하여 웹 애플리케이

developer.android.com

 

WebView.getSetting().setJavaScriptEnabled(true);

WebAppInterface webAppInterface = new WebAppInterface(context);

webView.addJavascriptInterface(webAppInterface, "AndroidBridge");

webView.loadUrl("file:///android_asset/index.html");

 

    public class WebAppInterface {
        private Context context;
        public WebAppInterface(Context context){
            this.context = context;
        }
        @JavascriptInterface
        public void sendMessageToNative(String msg) throws JSONException {
            // 웹에서 보낸 메시지를 처리
            JSONObject jsonObject = new JSONObject(msg);
            // JSON 객체에서 데이터 추출
            String inTestMode = jsonObject.getString("inTestMode");
            //Intent Request
            Spec.RequestData(intent);
            intent.putExtra("ResultType", 0);
            startActivityForResult(intent, 3000);
            }
        }
    }​
 
 
반응형