안드로이드 하이브리드앱에서 쿠키 사용 방법

 

 

 

 

 

 

 

 

 

 

WebView webview;
protected void onCreate(Bundle savedInstanceState) {
	CookieSyncManager.createInstance(this);
	webview = (WebView)findViewById(R.id.myWebView);

	try{
            cookieManager = CookieManager.getInstance();
            cookieManager.setAcceptCookie(true);
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
                cookieManager.setAcceptThirdPartyCookies(webview, true); // false 설정 시 오류 발생
            }
        }catch(Exception e){

        }
}

@Override
protected void onResume() {
	super.onResume();
	createIntroView();
	CookieSyncManager.getInstance().startSync();
}

@Override
protected void onPause() {
	super.onPause();
	CookieSyncManager.getInstance().stopSync();
}

@Override
protected void onPageFinished(WebView view, String url) {
	super.onPageFinished(view, url);
	    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
		CookieSyncManager.getInstance().sync();
	    }else{
		CookieManager.getInstance().flush();
	    }
}

 

참고, 쿠키를 이용한 자동로그인
https://sulkunblog.tistory.com/31
https://team404.tistory.com/13
https://stackoverflow.com/questions/2566485/webview-and-cookies-on-android

 

+ Recent posts