본문 바로가기

카테고리 없음

안드로이드 앱 카카오톡 공유하기 (4011오류) - 해결

0. 요약

  안드로이드에서 onCreateWindow, onCloseWindow 설정을 안하면... 4011 오류가 발생할 수 있습니다.

  태블릿에서요. 

  스마트폰에서는 거의 안나타나는 듯.. 

 

 

I. 원인
 1. 클릭하면 : intent가 아니라 https://~~ 로 시작
 1-1. javascript 가 작동안한다고 생각 하였으나.. 아님.

 1-2. 4011 오류가 나타남. 

II. 발단 
 1. 카카오 안드로이드 하이브리드 구현시 추가할 사항 문서를 보게 됨  
   https://developers.kakao.com/docs/latest/ko/javascript/hybrid

 2. 아래 코드를   WebviewActivity.java,  private void loadWebView(String url) 에 추가하였더니..  로그를 찍음. 

            @Override
            public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
                log.d("webview", "WebViewActivity --- window.open 협의가 필요합니다.");

                return true;
            }
            @Override
            public void onCloseWindow(WebView window) {
                 log.d("webview", "WebViewActivity --- onCloseWindow");
    }

  3. 그래서 아래와 같이 적용 



III. WebviewActivity.java 에서(예임. 각각의 웹뷰)

 1. 멀티윈도우 추가
        mWebView.getSettings().setDomStorageEnabled(true);
        mWebView.getSettings().setSupportMultipleWindows(true);


 2. 소스 출처 - https://hyedu.tistory.com/15


          /* 새창 */
            @Override
            public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
                log.d( "web", "WebViewActivity --- window.open 협의가 필요합니다.");

                WebView newWebView = new WebView(view.getContext());
                WebSettings settings = newWebView.getSettings();
                settings.setJavaScriptEnabled(true);
                settings.setJavaScriptCanOpenWindowsAutomatically(true);
                settings.setSupportMultipleWindows(true);

                final Dialog dialog = new Dialog(view.getContext(), R.style.Fullscreen);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(newWebView);
                dialog.show();
                dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
                    @Override
                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                        if(keyCode == KeyEvent.KEYCODE_BACK) {
                            if(newWebView.canGoBack()){
                                newWebView.goBack();
                            }else{
                                newWebView.setVisibility(View.GONE);
                                newWebView.destroy();
                                dialog.dismiss();
                            }
                            return true;
                        }else{
                            return false;
                        }
                    }
                });
                newWebView.setWebViewClient(new CustomWebViewClient(view.getContext()));
                newWebView.setWebChromeClient(new WebChromeClient() {
                    @Override
                    public void onCloseWindow(WebView window) {
                        dialog.dismiss();
                    }
                });

                WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
                transport.setWebView(newWebView);
                resultMsg.sendToTarget();

                return true;
            }
            @Override
            public void onCloseWindow(WebView window) {
                log.d("web", "WebViewActivity --- onCloseWindow");
                window.setVisibility(View.GONE);
                window.destroy();
                super.onCloseWindow(window);
            }