본문 바로가기

개발/Android 개발 주저리

Android 5.x 에서 PG결제시 페이지 로딩안되는 문제( Webview 오류 해결하기 )

오늘 서비스중인 앱에서 농협으로 결제시 결제가 안된다는 문의를 받았습니다.

보니까  Android5.0 / API LEVEL 21 부터 아래와 같은 내용이 추가되있더군요


If your app targets API level 21 or higher:
  • The system blocks mixed content and third party cookies by default. To allow mixed content and third party cookies, use the setMixedContentMode() and setAcceptThirdPartyCookies() methods respectively.
  • The system now intelligently chooses portions of the HTML document to draw. This new default behavior helps to reduce memory footprint and increase performance. If you want to render the whole document at once, disable this optimization by calling enableSlowWholeDocumentDraw().
  • If your app targets API levels lower than 21: The system allows mixed content and third party cookies, and always renders the whole document at once.


이말은 즉슨

웹뷰로 페이지를 띄우면 해당 페이지에서 처리되는 내용들의 쿠기가 설정에 따라 webview에서 block시켜버린다는 의미입니다

즉 일부 PG사들은. 아니 일부가 아니고 유일하게 농협 만안되는 겁니다


그럼 어떻게 해야할까요?

쿠기 옵션을 꺼주면 됩니다.



if (Build.VERSION.SDK_INT >= 21){
mWebview.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.setAcceptThirdPartyCookies(mWebview, true);}

간단하죠?

위 처럼 쿠키옵션을 직접 명시해주면 됩니다


MIXED_CONTENT_ALWAYS_ALLOW : 항상 허용

MIXED_CONTENT_COMPATIBILITY_MODE : 호환성 모드

MIXED_CONTENT_NEVER_ALLOW : 허용 안함


차고로 킷캣은 MIXED_CONTENT_ALWAYS_ALLOW 가 기본값입니다